Logic AND for Jquery selector

2020-04-03 04:03发布

I want to set to checked a checkbox input by value AND name..

<input name="email" type="checkbox" value="1" tabindex="2">

How can I do that? I need that both conditions are done.

This fails on &&

$("input[name=email] && [value='+i+']").attr('checked', true);

This code is into a for iteration and "i" is taking a numeric value. Thanks in advance for your time and help...

1条回答
做自己的国王
2楼-- · 2020-04-03 04:54

Just use both selectors next to each other:

$("input[name=email][value=" + i + "]").prop('checked', true);

Any selectors that have no space between them are applied to the same element.

查看更多
登录 后发表回答