views:

36

answers:

3

I want to select an html element with jquery using its attribute value.

I use $('td[i=0]') and it works correctly. What if i want to use 2 attribute together.

For example, I want to select td element with attributes i="0" and j="2" .

+5  A: 

You can just append them, e.g.:

('td[i=0][j=2]')

This works for pretty much any selector, adding them together without a space makes it check for the attribute on the same element.

Nick Craver
+1  A: 

Use $('td[i=o]' 'td[j=2]') ?

Ashley
+2  A: 

jQuery OR Selector:

$("td[i=0], td[i=2]")

jQuery AND Selector:

$("td[i=0][i=2]") 
Ayaz Alavi
your first answer is wrong, that will try and look for the element `td[i=0]` inside the element `td[i=2]`, the second param is used as a context so `sidebar = $('sidebar'); $boxes = $('.box',sidebar)`
RobertPitt
edited my answer, thanks +1 from me
Ayaz Alavi