Colon in Jquery selector

后端 未结 2 386
遇见更好的自我
遇见更好的自我 2021-01-28 01:54

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(

2条回答
  •  遇见更好的自我
    2021-01-28 02:34

    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:"]')
    

提交回复
热议问题