0

I am using :contains() to find strings in a large page of text content, and all of the repeating blocks will contain strings unique to those blocks, such as a student ID. I want to combine :contains() with :not(:contains()).

The logic is as follows: If string contains 1234, but the word "absent" is not present, append award statement

My goal is to combine the two selectors for a contains-but-doesn't-contain effect.

user1729506
  • 975
  • 4
  • 15
  • 28
  • 1
    possible duplicate of [jQuery "not contains" selector](http://stackoverflow.com/questions/20062085/jquery-not-contains-selector) – Dinei Sep 24 '15 at 19:33
  • Possible solution: `$('div:contains(1234):not(:contains(absent))')` and [DEMO](https://jsfiddle.net/lmgonzalves/teeapgcz/). – lmgonzalves Sep 24 '15 at 19:33

1 Answers1

2

You can use filter here:

$(selector).contains("1234").filter(function () {
  return $(this).not(":contains("absent")");
});

Or in simple way:

$('selector:contains(1234):not(:contains(absent))')
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252