开发者

jQuery: looking through a DIV, getting name that contains WITH id that contains

开发者 https://www.devze.com 2023-02-04 23:25 出处:网络
I\'ve got a very interesting need for jQuery. I need to look into a specific DIV ID and then within that DIV, find an input thats name contains a certain string but is also checked.

I've got a very interesting need for jQuery.

I need to look into a specific DIV ID and then within that DIV, find an input thats name contains a certain string but is also checked.

var exclusionsFridayChecked = $("#divExclusions").find("input[id~='Fridays'][typ开发者_运维技巧e='checked']").length;

// hoping to get '1' if it is checked

But that doesn't work... my syntax is off.


The ~= selector "selects elements that have the specified attribute with a value containing a given word, delimited by spaces".

Since ids cannot contain spaces, I'm guessing that you want *=, which "selects elements that have the specified attribute with a value containing the a given substring".

So, you can try using

$("#divExclusions input[id*='Fridays']:checked")


///.length should be a function so .length() EDIT: NOT WORKING

Maybe jQuery returns as an array so you could try using $("#divExclusions").find("input[id~='Fridays'][type='checked']")[0].length

0

精彩评论

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