I am stuck using my own DOM methods (I know, right?), And I have a structure like this:
<div>
<input>
<a>
</div>
I use onClick in the tag <a>and want to get the value from the input. On Chrome / OS X, something like
this.previousSibling.previousSibling.value
will work well. I double it because the first .previousSiblingreturns a <div>Textnode, and another one to the one that gets the input I need.
My question is: .previousSiblingalways returns the parent text of the node, if it exists?
Thank!
EDIT / Solution
My hacked solution was (cross-browser) to make sure I get the right item:
var el = this;
while(el.nodeType == 3 || el.tagName && el.tagName !== 'INPUT') {
el = el.previousSibling
};
console.log(el.value);
, -, , onClick . , ( HTML )