开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜