Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery "contains" multiple values

I am finding all the divs in a document which contains inside a text: 'thetext' and i am changing this text:

$("div:contains('thetext'):not(:has(*))").each(function () {

  $(this).text($(this).text() + " anotherTextAddedBefore");

 })

Is it possible to put inside contains multiple values? I would like to find the divs whic contains: 'thetext', but also another values, for example: 'thetext1', 'thetext2',etc

I`d want to make it in one procedure and not in more: dont want to use as many procedures as texts i´d like to find.

Thanks!

like image 409
Za7pi Avatar asked Apr 23 '14 15:04

Za7pi


2 Answers

You can use the multiple selector as a or condition like

$("div:not(:has(*))").filter(":contains('thetext'), :contains('thetext2')").each(..)
like image 93
Arun P Johny Avatar answered Sep 21 '22 22:09

Arun P Johny


A selector like this provides an OR condition -

$("div:contains('thetext'), div:contains('thetext1'), div:contains('thetext2')")

A selector like this provides an AND condition -

$("div:contains('thetext'):contains('thetext1'):contains('thetext2')")

Demo - http://jsfiddle.net/jayblanchard/3a72h/

like image 41
Jay Blanchard Avatar answered Sep 23 '22 22:09

Jay Blanchard