Skip to content Skip to sidebar Skip to footer

Colon In Jquery Selector

I have recntly updated my jquery from 1.4 to 2.1 and an error started appeared. In my code I have a part where I select the elements with by an id. jQuery('*[id^=name:]') That prod

Solution 1:

you can wrap the attribute value like a string literal

jQuery('*[id^="name:"]')

Demo: Fiddle

Solution 2:

You can escape it by double backslashes. From the docs:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\

jQuery("*[id^=name\\:]")

or wrap your value inside double quotes:

jQuery('*[id^="name:"]')

Post a Comment for "Colon In Jquery Selector"