开发者

Why is this Jquery Selector not working?

开发者 https://www.devze.com 2023-03-25 05:53 出处:网络
I\'m trying to select all the textboxes that have the class foo. Doing: console.log( $(\"input .foo\") );

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

0

精彩评论

暂无评论...
验证码 换一张
取 消