I am learning the basics of HTML. I have the following code:
alert(document.querySelector('div:nth-child(1)').childNodes[0].textContent.trim().length > 0)
<div>
<label>Name</label><br/>
<input type="text"><br/>
<label>Password</label><br/>
<input type="password">
</div>
<div>
<input name="gender " type="radio">
<label>Male</label>
<input name="gender " type="radio">
<label>Female</label>
<input name="gender " type="radio">
<label>Others</label>
</div>
<div>
<input name="answer" type="checkbox">
<label>Answer 1</label>
<input name="answer" type="checkbox">
<label>Answer 2</label>
<input name="answer" type="checkbox">
<label>Answer 3</label>
<input name="answer" type="checkbox">
<label>Answer 4</label>
</div>
<div>
<input type="submit" value="Submit">
</div>
I expected the result to be true, since the first element of the first <div> is a <label>, which contains a string of non-zero length. The actual result is false, however. Why?