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.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With