html - Javascript getElementsByTagName - include embedded elements -


i using fragment of javascript internet collect <small></small> elements within div id 'footnotes' , append them ordered list @ end of document, links , links (i.e easy html footnotes), footnotes.js:

var domsupport = document.getelementsbytagname && document.createelement;  window.onload = function() {     if (!domsupport) return;      var footnoteholder = document.getelementbyid('footnotes');     var allnotes = footnoteholder.getelementsbytagname('small');     var noteslist = document.createelement('ol');      noteslist.classname = 'noteslist';      (var = 0; < allnotes.length; i++) {         var newa = document.createelement('a');         newa.id = 'text-' + (i + 1);         newa.setattribute('href', '#footnote-' + (i + 1));         newa.setattribute('title', 'jump footnote');         newa.appendchild(document.createtextnode((i + 1)));          newbacklink = document.createelement('a');         newbacklink.id = 'footnote-' + (i + 1);         newbacklink.setattribute('href', '#text-' + (i + 1));         newbacklink.setattribute('title', 'back text');         newbacklink.appendchild(document.createtextnode('[back]'));          newnote = document.createelement('li');         newnote.appendchild(document.createtextnode(allnotes[i].firstchild.nodevalue + ' '));         newnote.appendchild(newbacklink);         noteslist.appendchild(newnote);          allnotes[i].replacechild(newa, allnotes[i].firstchild);     }     footnoteholder.appendchild(document.createelement('hr'));     footnoteholder.appendchild(noteslist); } 

i simplicity, no jquery in sight, able include line breaks <br> and/or links <a href="https://www.ncbi.nlm.nih.gov/pubmed/27827297">click pubmed</a> inside of footnotes.

when try include other elements within <small></small> tags text placed within body - not collected , placed @ end. e.g.

<!doctype html> <html> <head> <title>mdt home</title> </style> <script type='text/javascript'      src='..\..\js\footnotes.js'> </script> </head> <body> <span id='footnotes' ><br>  <h2>welcome mdt site<br></h2><br> have designed site in minimalist style using <a href='https://www.lua.org/' title='lua'>lua</a> should run on trust machines.<br> <br> use menu click icon @ top left. if have modern browser can use keyboard shortcuts  [<small> alt-m: menu.<br> alt-h: mdt home.<br> alt-k: hip , knee.<br> alt-a: foot , ankle.<br> alt-w: wrist , hand.<br> alt-s: shoulder , elbow.<br> alt-i: spine.<br> alt-c: children.<br> </small>] e.g move menu entering alt-m.  please read terms of use before proceeding review patient data. <br>  <br></span> </body> </html> 

i'm not sure if problem lies selection of allnotes using getelementsbytagname('small') producing nodelist object, or problem building of newnote using allnotes[i].firstchild.nodevalue + ' ' .

sorry don't have original source of fragment longer - credit author - , ask them directly. in ideal world learn javascript instead of culling fragments , pasting pages.

any gratefully received.

gavin

spurred on criticism have examined each line of code find why can't have elements in footnotes.

it appears can't have elements within textnodes. post mr thomas aware of, having contributed in comments.

i not learning javascript find alternative mechanism of collating fragments may or may not contain elements. know there bits of javascript, dom coding not seem 1 of them.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -