New course! Every coder should learn Generative AI!
Try a free lesson0
<input type="number" id="first" value=" "><button onclick=" myfunc()>closing tag> , how to take value of input length,
I want value of input element but directly as an argument of myfunc(length), for example, sometime we use myfunc(this.value), but now , since value belong to other tag, so how to take value of other tag in my example,
2 Answers
+ 4
You can do:
myfunc(this.parent.firstChild.value);
... or something like that, depending on the html context ^^
Anyway, this could becomes a little tricky, as some browsers considerate empty node text in child elements list, and other not :P So, safer to do something like:
myfunc(this.parent.getElementsByTagName('input')[0].value);
Or you can use window.queryQuerySelctor() to select your input with an absolute css path selector string, avoidind the use of 'this' ;)
0
I do know getElement method, so except that..