I have this DOM tree:
<li>
data ....
<br>
data ...
<img ... />
<br>
<script> ... </script>
<span> data ... </span>
</li>
how can I loop through the children of the above li element that fall between the li itself and script element, i.e. script and span elements are out of the loop ... thanks in advace !!
note: I do not want to use JQuery, because my app is using Protoype and it will conflict with JQuery if I use both of them together, i'd appreciate it if there's a quick solution using Prototype.
would something like this work for you?
var child = liElement.firstChild;
while(child){
if(child.nodeName.toLowerCase() == 'script'){
break
}
//do your stuff here
child = child.nextSibling;
}
Note, the if the "data" in your example are strings, these will exist in the child heirarchy as instances of textNodes. if you need to do special processing on this stuff, you will want to do a check such as
switch(child.nodeType){
case 3:
//text Node
break;
case 1:
//Element node
break;
default:
//break;
}
check out https://developer.mozilla.org/en/nodeType for more node types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With