0

Is it possible words in a jquery selector line. For example if i wanted to use yellow and blue could i just include it somehow by adding a colon or something or do i have to repeat the script over and over for each word.

 <script>  
 
$(document).ready(function(){
 $("p:contains(yellow)").css(
  {"background-color":"lightblue",
   "color":"darkblue",
   "border":"1px inset dodgerblue",
   "border-radius":"10px",
   "padding":"3px 10px",
   "font-size":"18px",
   "font-family":"arial",
   "text-shadow":"1px 2px 3px blue"
  });
  });   
  
 </script>

The script that i am using above does not seem to allow this, perhaps i am approaching this all wrong, i have tried different seperators such as the comma, colon, semicolon. what i am looking for is some like the snippet below.

$("p:contains(yellow, blue, green)")

Any help would be appreciated

Thanks

Ray
  • 37
  • 5
  • Does this answer your question? [Jquery "contains" multiple values](https://stackoverflow.com/questions/23248809/jquery-contains-multiple-values) – User863 Sep 05 '21 at 08:09

1 Answers1

0
$('p:contains("yellow"):contains("blue"):contains("green")').      // Both yellow AND blue AND green
$('p:contains("yellow"), p:contains("blue"), p:contains("green")').  // Either yellow OR blue or green
navnath
  • 3,548
  • 1
  • 11
  • 19
  • Hi all, sorry first solution does not work, the solution offered by Navnath is exactely the idea i had in my head when posing the question however what it does, is to ignore all the contains and only action the last one, meaning that only 'green' is executed. – Ray Sep 05 '21 at 13:26
  • So you want to apply css to all paragraphs with yellow, blue, green text? – navnath Sep 05 '21 at 15:23