Jump to content

from childNode to the brother from the father


sonicred

Recommended Posts

child = "form[check11][]"brother= <label>father =<td>end result: get the info from label.HiAt the moment i used document.getElementsByName('form[check11][]') .I can't use document.getElementById because the id sometime it's check11, order time check110 etc..It's not safe to use for me..Is is there a way that i can get from "form[check11][]" to the label.innerHTML because i need the xxxx

<tr class="form-block form-block-check11">	<td>		<input name="form[check11][]" value="790" id="check110" type="checkbox">		<label for="check110">xxxxxx</label>		<div class="formClr"></div><span id="component4012" class="formNoError">Invalid Input</span>	</td></tr>

p.s i bypass it and found a other solution: for(j=0;j<_idx2;j++) {var parmId = document.getElementsByName('form['+param+'][]').getAttribute('id'); if(document.getElementsByTagName('label')[j].getAttribute('for') == parmId ) {checklist += document.getElementsByTagName('label')[j].innerHTML ;but still i wonder if it can be diffrent and beter..

Link to comment
Share on other sites

The trick, as the tutorial shows, is to skip over the text nodes that contain your tabs and line breaks. nextElementSibling will do that, but it is not universally supported (and won't be for a while, considering the half-life of legacy browsers).

Link to comment
Share on other sites

  • 2 weeks later...

See if you can figure it out using my example. All I did was take the Try-it example for nextSibling and modify it to look like an html document.

<html><head><script type="text/javascript">//check if the next sibling node is an element nodefunction get_nextsibling(n) {	x=n.nextSibling;	while (x.nodeType!=1) {		x=x.nextSibling;	}	return x;}function siblingTest(el) {	var container = document.getElementById("container");	var str = "Start at: "+el.nodeName;	var sibling = get_nextsibling(el);	str += "<br />Next sibling: "+sibling.nodeName;	container.innerHTML = str;}</script></head><body><div style='border: 1px solid'>	<input type='button' value='Find Sibling' onclick='siblingTest(this);' />	<span>This is a span</span>	<div id='container'></div></div></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...