Sungguk Lim
Sungguk Lim

Reputation: 6228

jquery select by two condition

I like to select an element by more than two condition.

for example

name is some name and checked

how can I do this?

Upvotes: 1

Views: 1637

Answers (3)

Sarfraz
Sarfraz

Reputation: 382836

You can do like this:

if ($('input[name="some_name"]').is(':checked'))
{
  // your code here...........
}

This makes sure that it checks only for form input which is exactly what you are looking for.

Upvotes: 0

Kronass
Kronass

Reputation: 5406

jQuery uses CSS Selector rules for document matchings. if you know how to use CSS Selectors you will know how to do this use this as reference http://api.jquery.com/category/selectors/

and read more about CSS Selectors

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630559

You can append the attribute and :checked selectors, like this:

$("[name=myName]:checked")

Th key here, don't leave a space and you're telling Sizzle (jQuery's selector engine) to filter on the same element. If you put a space between, it's would be: "find checked children of elements with this name."

Upvotes: 5

Related Questions