I am using a JavaScript function which fills nodes in the condition some append child (document. Something like getElementById ("foo")) . However, I do not have complete control over the surrounding code and it is likely that some element will be the same ID. Consider the following:
& lt; Div id = "foo" & gt; & Lt; Span id = "bar" & gt; 456 & lt; / Span & gt; & Lt; Script type = "text / javascript" & gt; Document.log (document.getElementById ("bar"). InnerText); & Lt; / Script & gt; & Lt; / Div & gt; & Lt; Hour & gt; & Lt; Div id = "foo" & gt; & Lt; Span id = "bar" & gt; 123 & lt; / Span & gt; & Lt; Script type = "text / javascript" & gt; Document.log (document.getElementById ("bar"). InnerText); & Lt; / Script & gt; & Lt; / Div & gt; In most browsers, the output will be: 456 456 123 456
instead of what I want, which
456 456 123 123
This result is not completely disappointed for me; I think why this is happening, I was expecting that I could do more than one JavaScript call
document.write (myscriptnode.parent.childnodes ['bar']. InnerText) < / Code>
Let's say I have nothing but control of script tags , is there a way to accomplish this?
About using javascript libraries such as jQuery, which lets you find CES-selector-like-syntax getElementById Allows the writing of insecurities, and helpful helpful methods such as parents ()
Comments
Post a Comment