Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery multiple selectors with AND OR condition

If I have a table which has 4000 rows

<table>
<tr class="a b c d e f g"><td>xxx</td></tr>
<tr class="a c d e f g"><td>xxx</td></tr>
<tr class="d e f g"><td>xxx</td></tr>
<tr class="a d e f g"><td>xxx</td></tr>
.
.
.
.
.
</table>

If I want to select rows which have classes (a or b or c) and (d or e) and (a or g)

How can I code the selector statement?

Thanks

like image 264
Kay Li Avatar asked Jul 18 '13 16:07

Kay Li


People also ask

Can we use multiple selectors in jQuery?

jQuery - Multiple Elements SelectorYou can specify any number of selectors to combine into a single result.

How do you target multiple elements in jQuery?

To select multiple elements of an html page using multiple elements selector, we pass the element names inside parenthesis, in double quotes, separated by commas. For example: $(“div, p, h2”) this will select all the div, p and h2 elements of a page.

How do you select multiple elements in Javascript?

Use the querySelectorAll() method to select elements by multiple ids, e.g. document. querySelectorAll('#box1, #box2, #box3') . The method takes a string containing one or more selectors as a parameter and returns a collection of the matching elements.


1 Answers

Try this:

$('.a, .b, .c').filter('.d, .e').filter('.a, .g')
like image 102
Manoj Yadav Avatar answered Oct 19 '22 23:10

Manoj Yadav