Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div:contains not a valid selector

I'm following this example and typed $( "div:contains('John')" ).css( "text-decoration", "underline" ); , but got an exception:

VM23376:1 Uncaught DOMException: Failed to execute '$' on 'CommandLineAPI': 'div:contains('John')' is not a valid selector.

like image 798
Kys Plox Avatar asked Mar 18 '17 16:03

Kys Plox


2 Answers

function '$' is unknow. You probably trying to execute this code in place where jQuery library wasn't loaded.

$( "div:contains('John')" ).css( "text-decoration", "underline" );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
John
</div>
like image 95
Dawid Wekwejt Avatar answered Nov 17 '22 08:11

Dawid Wekwejt


enter image description here

it works for me as expected without an error as you can see the screenshot.

you can run this link also click on this link to see example

<!doctype html>
   <html lang="en">
       <head>
          <meta charset="utf-8">
          <title>contains demo</title>
          <script src="https://code.jquery.com/jquery-3.5.0.js">. 
         </script>
        </head>
  <body>
    <div>John Resig</div>
    <div>George Martin</div>
    <div>Malcom John Sinclair</div>
    <div>J. Ohn</div>
    <script>
      $("div:contains('John')").css("text-decoration", 
         "underline");</script>
  </body>

</html>
like image 1
Muneer Khan Avatar answered Nov 17 '22 10:11

Muneer Khan