-1

How do I select the following element using the JQuery :contains pseudo class?

<div class='tab'>A & B</div>

I have tried the following all of which do not work.

$('.tab:contains("A & B")')
$('.tab:contains("A &amp; B")')
$('.tab:contains("A \0026 B")')
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
jax
  • 37,735
  • 57
  • 182
  • 278
  • Can't reproduce: https://jsfiddle.net/kyjkmLhr/ – vaultah Mar 08 '16 at 09:26
  • Well, for one thing, that's not CSS. If you're looking for a CSS-based solution as your tags imply, then [there isn't one](http://stackoverflow.com/questions/1520429/is-there-a-css-selector-for-elements-containing-certain-text). – BoltClock Mar 08 '16 at 09:30
  • @BoltClock mmmm, I thought it was core css. Have updated to JQuery. – jax Mar 08 '16 at 09:43

1 Answers1

1

the first seems to work

$('.tab:contains("A & B")').css('color','red')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class='tab'>A & B</div>
maioman
  • 18,154
  • 4
  • 36
  • 42
  • you beated me on time, +1 – silviagreen Mar 08 '16 at 09:27
  • Don't have the code with me right now but I will try again tomorrow. I guess it must be something else going on. The actual data is being read from a [yadda table](https://acuminous.gitbooks.io/yadda-user-guide/content/en/feature-specs/example-tables.html). Maybe it is doing something weird when reading the & character. – jax Mar 08 '16 at 09:45