Why is this Jquery Selector not working?
I'm trying to select all the textboxes that have the class foo. Doing:
console.log( $("input .foo") );
doesn't work, however doing
co开发者_C百科nsole.log( $(".foo") );
works. Why is this? What am I doing wrong?
JQuery selectors are just like CSS selectors. You want
$("input.foo");
What you had, $("input .foo")
was selecting all descendants with class foo of any <input> element.
The space is what's doing it. Should be $("input.foo")
The way you have it, it's looking for elements with class foo
inside of an input
.
input
can't have children -- just like an img
element
精彩评论