View Full Version : Denoting current position in doc without using ID attribute?

11-01-2002, 01:26 AM
I was wondering, let say I have the following HTML fragment:

<b>this is some text<b>
<span>This is some more text<span>

//my script here

and inside the script above, I wish to gain access to the elements and text above. Is it possible to do so without having to explicitly denote an ID attribute somewhere to use as the starting pointing? Something like:

currentposition.previousSibling //should return <span> tag


11-01-2002, 01:34 AM
Not easily.

Your first line in the <script> tag could be something like:


Then you can iterate through the document.getElementsByTagName('script') HTMLCollection until you find one with firstChild.nodeValue.indexOf('//identifier') == 0, but that seems a little inefficient.

You could always give your <script> an id, but you seem to want otherwise.

11-01-2002, 01:36 AM
Thanks jkd. It just occurred to me that a good compromise would be to give the SCRIPT tag an ID attribute. I don't have physical access to any of the HTML codes above, FYI.

Great minds think alike I guess :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum