Home >Web Front-end >JS Tutorial >Detailed explanation of jquery :hidden selector selecting
jquery: Why does the hidden selector select the221f08282418e2996498697df914ce4e tag
<html> <head> <title>forth.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../jquery.min.js"> </script> </head> <body> <form action="#" id="form1"> <select> <option>Option</option> </select> <input type="hidden"/><div style="display:none">test</div> </form> </body> <script type="text/javascript"> alert($("#form1 :hidden").length); </script> </html>
Why the result Is it 3 instead of 2? Thanks.
console.log($("#form1 :hidden"))You will know in a moment. What is selected is not 221f08282418e2996498697df914ce4e, but the 5a07473c87748fb1bf73f23d45547ab8 inside:
[option, input, div]
Just use $("#form1 > :hidden") to select, so that only the form will be selected. direct child element, so option
select has no closing tag?
Because you selected a hidden label, and option is a hidden label. . select is not hidden so it will not be selected,
The above is the detailed content of Detailed explanation of jquery :hidden selector selecting