{"id":21548,"date":"2016-04-26T03:01:55","date_gmt":"2016-04-25T17:01:55","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=21548"},"modified":"2016-04-26T19:41:30","modified_gmt":"2016-04-26T09:41:30","slug":"htmljavascript-dom-cloning-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-dom-cloning-primer-tutorial\/","title":{"rendered":"HTML\/Javascript DOM Cloning Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/wordcategories.htm\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript DOM Cloning Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/WordCategoriesCloningGame.jpg\" title=\"HTML\/Javascript DOM Cloning Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript DOM Cloning Primer Tutorial<\/p><\/div>\n<p>Javascript <a target=_blank title='(Javascript) DOM information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Document_Object_Model'>DOM<\/a> is hugely useful for creating dynamic client functionality for web pages.  And we don&#8217;t mean for you to &#8220;Hug Ely&#8221; <font size=1>&#8230; though you can if he&#8217;s right next to you &#8230;<\/font> we mean, primarily for us, the following http:\/\/localhost:8888 MAMP web page code type Javascript DOM usage statistical table of Javascript DOM property usage findings &#8230;<\/p>\n<table>\n<tr>\n<th>http:\/\/localhost:8888\/<\/th>\n<th>*.htm<\/th>\n<th>*.html<\/th>\n<th>*.js<\/th>\n<th>*.php<\/th>\n<\/tr>\n<tr>\n<td>Count<\/td>\n<td>68<\/td>\n<td>1333<\/td>\n<td>53<\/td>\n<td>311<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .id usage<\/td>\n<td>63<\/td>\n<td>478<\/td>\n<td>93<\/td>\n<td>168<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .classname usage<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .title usage<\/td>\n<td>103<\/td>\n<td>551<\/td>\n<td>126<\/td>\n<td>512<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .src usage<\/td>\n<td>76<\/td>\n<td>508<\/td>\n<td>113<\/td>\n<td>190<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .href usage<\/td>\n<td>73<\/td>\n<td>352<\/td>\n<td>48<\/td>\n<td>1009<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .value usage<\/td>\n<td>386<\/td>\n<td>2565<\/td>\n<td>431<\/td>\n<td>1524<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .innerHTML usage<\/td>\n<td>283<\/td>\n<td>2613<\/td>\n<td>464<\/td>\n<td>1243<\/td>\n<\/tr>\n<tr>\n<td>Count DOM .outerHTML usage<\/td>\n<td>3<\/td>\n<td>4<\/td>\n<td>0<\/td>\n<td>11<\/td>\n<\/tr>\n<\/table>\n<p> &#8230; and it is no surprise to me that Javascript DOM property .<a target=_blank title='HTML innerHTML property information' href='http:\/\/www.w3schools.com\/jsref\/prop_html_innerhtml.asp'>innerHTML<\/a> almost tops the bill, with its usefulness on scenarios like yesterday&#8217;s <a target=_blank title='Canvas Annotation Email Attachment Snapshots Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/canvas-annotation-email-attachment-snapshots-tutorial\/'>Canvas Annotation Email Attachment Snapshots Tutorial<\/a> dynamically creating and building up HTML select &#8220;dropdown&#8221; elements.<\/p>\n<p>But why so little use of the Javascript DOM property .<a target=_blank title='HTML outerHTML property information' href='http:\/\/help.dottoro.com\/ljloliex.php'>outerHTML<\/a>?  Well, this property has not always been fully supported by all web browsers and has been known to cause <a target=_blank title='OutHTML property' href='http:\/\/w3schools.invisionzone.com\/index.php?s=ac984a4e6679fdaf3e2bb89387d8906f&#038;showtopic=54860&#038;hl='>problems<\/a> on occasions.<\/p>\n<p>Nevertheless, Javascript DOM property .<a target=_blank title='HTML outerHTML property information' href='http:\/\/help.dottoro.com\/ljloliex.php'>outerHTML<\/a> has usefulness regarding HTML element text reformatting, and we find a use today using it to &#8220;clone&#8221; an existing web page into other &#8220;clone&#8221; web pages opened in popup windows via Javascript <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/met_win_open.asp' title='window.open information from w3schools'>window.open<\/a> that we apply to the web pages of <a title='HTML\/Javascript Word Categories Game Tutorial' href='#hjwct'>HTML\/Javascript Word Categories Game Tutorial<\/a> as shown below.<\/p>\n<p>Maybe you see a small &#8220;cloning accuracy&#8221; improvement with the retention of the document body yellow background colour because of the <i>totalclone<\/i> use of <i>document.body.outerHTML<\/i> rather than (the <i>clone<\/i>) via the use of the concatenation of the document body element constituent outerHTML parts.<\/p>\n<p><code><br \/>\n    clone=window.open('','_blank','top=60,left=60,width=950,height=700');<br \/>\n    clone.document.write(\"&lt;html&gt;\" + document.head.outerHTML.replace('function goaga' + 'in() {', 'function goaga' + 'in() { return; ') + \"&lt;body&gt;\" + h1s[0].outerHTML.replace('Categories Game', 'Categories ' + five + ' Second Game') + h3s[0].outerHTML + divs[0].outerHTML + \"&lt;\/body&gt;\" + \"&lt;\/html&gt;\");<br \/>\n    totalclone=window.open('','_blank','top=60,left=160,width=950,height=700');<br \/>\n    totalclone.document.write(\"&lt;html&gt;\" + document.head.outerHTML.replace('function goaga' + 'in() {', 'function goaga' + 'in() { return; ') + document.body.outerHTML.replace('Categories Game', 'Categories ' + five + ' Second Game') + \"&lt;\/html&gt;\");<br \/>\n<\/code><\/p>\n<p>Today we have HTML and Javascript programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/wordcategories.html-GETME\" title='wordcategories.htm'>wordcategories.html<\/a> which changed from the non-cloning version below <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/wordcategories.html-GETME\" title='wordcategories.htm'>this way<\/a> and which has a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/wordcategories.htm\" title='Click picture'>live run link<\/a>.<\/p>\n<p>Perhaps you can see further uses for .outerHTML in other non-mission-critical scenarios.  If useful, am sure you&#8217;ll find your code a lot shorter than if you use .innerHTML equivalent functionalities.<\/p>\n<hr>\n<p id='hjwct'>Previous relevant <a target=_blank title='HTML\/Javascript Word Categories Game Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-word-categories-game-tutorial\/'>HTML\/Javascript Word Categories Game Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Word Categories Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/WordCategoriesGame.jpg\" title=\"HTML\/Javascript Word Categories Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Word Categories Game Tutorial<\/p><\/div>\n<p>Do you like word games?  Today&#8217;s game asks you to categorize words &#8230; we&#8217;re going to call the game <i>&#8220;The Word Categories Game&#8221;<\/i> (too snappy for you?!) &#8230; and you score points (you get more points for advanced word categorizations) for each correct word you supply that satisfies the requirements.  It uses English words, based on the dictionary arrangements at its (web) server.   Maybe it would be a good game to learn English vocabulary.<\/p>\n<p>Today&#8217;s data source is a book called <i>Five-Minute Activities<\/i> by Penny Ur and Andrew Wright.   We thank this source for their great Categories word list on pages 6 and 7.<\/p>\n<p>This <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/\" title=\"Categories Game\">game<\/a> uses HTML and Javascript programming languages.<\/p>\n<p>Hopefully you can figure the rules when you click the picture above for a <a target=_blank title=\"live run\" href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/\">live run<\/a>.<\/p>\n<p>Another thank you to <a target=_blank title='The Free Dictionary' href='http:\/\/thefreedictionary.com'>The Free Dictionary<\/a> for its great online presence as a dictionary resource, for the functionality to explain an unknown or incomplete answer for the word in question, for its dictionary meaning.  The image map &#8220;click parts of the picture&#8221; <a target=_blank title='Pointed at vocabulary tutorials' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=vocabulary'>vocabulary ESL tutorials<\/a> at this blog use the same resource to explain dictionary information about clicked on &#8220;things&#8221;.<\/p>\n<p>Programming features of this program are the Javascript use of <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp' title='Javascript eval'>eval<\/a> and  <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/met_doc_write.asp' title='Javascript document.write'>document.write<\/a> to make use of pre-defined arrays.  Read more about Javascript eval with a previous tutorial called <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3800' title='PHP\/Javascript Eval Primer Tutorial'>PHP\/Javascript Eval Primer Tutorial<\/a>.<\/p>\n<p>Anyway, see how you go with this organizational game!<\/p>\n<p>Thanks to Mobilefish for ImageMap service at <a target=_blank title='Mobilefish ImageMap service' href='http:\/\/www.mobilefish.com\/services\/image_map\/image_map.php'>http:\/\/www.mobilefish.com\/services\/image_map\/image_map.php<\/a>.<\/p>\n<p>Here is a link to some downloadable HTML (with Javascript) programming code you could rename to <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/WordCategories\/wordcategories.html_GETME\" title=\"=wordcategories.html\">wordcategories.html<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#7892' onclick='var dv=document.getElementById(\"d7892\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=ESL\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7892' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#21548' onclick='var dv=document.getElementById(\"d21548\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/OTblog\/tag\/dom\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d21548' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Javascript DOM is hugely useful for creating dynamic client functionality for web pages. And we don&#8217;t mean for you to &#8220;Hug Ely&#8221; &#8230; though you can if he&#8217;s right next to you &#8230; we mean, primarily for us, the following &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-dom-cloning-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[354,1549,576,1525,652,1861],"class_list":["post-21548","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-dom","tag-element","tag-html","tag-innerhtml","tag-javascript","tag-outerhtml"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21548"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=21548"}],"version-history":[{"count":18,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21548\/revisions"}],"predecessor-version":[{"id":21596,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/21548\/revisions\/21596"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=21548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=21548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=21548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}