2

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

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

jQuery OR Selector:

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

jQuery AND Selector:

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

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.