Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic AND for Jquery selector

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...

like image 989
chespinoza Avatar asked Feb 05 '13 20:02

chespinoza


People also ask

What are the selectors of jQuery?

jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.

How jQuery selectors are executed?

jQuery selector: jQuery selectors are used to selecting the HTML element(s) and allow you to manipulate the HTML element(s) in a way we want. It selects the HTML elements on a variable parameter such as their name, classes, id, types, attributes, attribute values, etc. Example: HTML.

Which is the fastest selector in jQuery?

ID Selector: The jQuery #id selector selects the element on the basis of the ID attribute of the HTML tag. This selector is basically used when we have to work on a single element because an ID should be unique within a web page.

How many types of jQuery selectors are there?

So far we have covered only three standard jQuery Selectors.


1 Answers

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.

like image 121
Joseph Silber Avatar answered Sep 26 '22 05:09

Joseph Silber