[0] First not to assign id a numeric. It is no good, period. Also [tt]<li="2">[/tt] is not serious.
[1] Suppose you have this.
[tt]
<ul id="id1">
<li id="id2">bla</li>
</ul>
<ul id="id3">
<li>bla</li>
</ul>
[/tt]
[1.1] Starting from assumption you've got the reference to id="id1", via say getElementById() method. Then you can do this.
[tt]
var onode, otarget;
onode=document.getElementById("id1");
while (onode) {
onode=onode.nextSibling;
if (onode.nodeType==1) {
otarget=onode;
break;
}
onode.nextSibling;
}
if (otarget) {
//you actually have found one, and do something here
alert(otarget.id + "\n" + otarget.tagName); //just to verify
} else {
//you don't find one
}
[/tt]
amendment
I have misplaced a nextSibling line. Here is a retake.
[tt]
var onode, otarget;
onode=document.getElementById("id1");
[blue]onode=onode.nextSibling;[/blue]
while (onode) {
[red]//[/red]onode=onode.nextSibling;
if (onode.nodeType==1) {
otarget=onode;
break;
}
onode.nextSibling;
}
if (otarget) {
//you actually have found one, and do something here
alert(otarget.id + "\n" + otarget.tagName); //just to verify
} else {
//you don't find one
}
[/tt]
amendment-2
Sorry.
[tt]
var onode, otarget;
onode=document.getElementById("id1");
[blue]onode=onode.nextSibling;[/blue]
while (onode) {
[red]//[/red]onode=onode.nextSibling;
if (onode.nodeType==1) {
otarget=onode;
break;
}
[red]onode=[/red]onode.nextSibling;
}
if (otarget) {
//you actually have found one, and do something here
alert(otarget.id + "\n" + otarget.tagName); //just to verify
} else {
//you don't find one
}
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.