<div class="tab">Question 1 of 12
<p><input type="radio" name="gender" value="male">Male</p>
<p><input type="radio" name="gender" value="female">Female</p>
</div>
I have a couple of elements with the same html format as above, and i'm trying to perform some operation in which i'll need the value of the name property,
var x = document.getElementsByClassName("tab")
var y = x[0].getElementsByTagName("input")
in this case, y[0].name
should evaluate to "gender", instead it evaluates to false as does all other input name properties. Is there a reason for this?
This fragment seems to be ok.
y[0].name returns 'gender' as expected.
It's probably something else in your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.