javascriptjqueryjquery-selectors

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.


Solution

  • Because of the reference to CommandLineAPI in the error, I am pretty sure this is not jQuery, but the command-line version of $ utility that is loaded in the chrome console. I can reproduce the error on Chrome 57, bot not on Chrome 125, so somewhere in between those two versions this issue was fixed. Lesson learned is be careful when using $ in the chrome console.