jQuery selector bug? composed selector vs. simple selector & find()

ぃ、小莉子 提交于 2019-12-06 04:21:46

What you really want is:

$("#selector > :radio")

As for why you're getting only one, I'd need to see the actual code that's being run because find() doesn't stop at one and will find all matches so it may be how you're using it afterwards that is the issue.

The two code fragments should return the same result.

Are you saying that when you run the following code, the first alert will show "3" and the second "1" ?

var a = $("#selector input[type=radio]");
var b = $("#selector").find("input[type=radio]");

alert(a.length);
alert(b.length);

Can you please verify?

Try

$("#selector").find("input[type=radio]")

See here

All the three returns the same result!

$(function() {
    console.log($("#selector input[type=radio]"));          // 3
    console.log($("#selector").find("input[type=radio]"));  // 3
    console.log($("#selector").find("input"));              // 3
});

$("#selector").children("input[@type=radio]")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!