this.nextSibling not working
问题 I expect the following code to alert "out" <input type=text onfocus="alert(this.nextSibling.id)" /> <output id="out">this is output</output> But it alerts undefined WHY? 回答1: nextSibling selects the very next sibling node of the element. The very next node can also be a textNode which doesn't have an id property, hence you get the undefined value. As the other answer suggests you could use the nextElementSibling property which refers to the next sibling node that has nodeType of 1 (i.e. an