Colon in Jquery selector

后端 未结 2 357
遇见更好的自我
遇见更好的自我 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:"]')
    
    0 讨论(0)
  • 2021-01-28 02:38

    you can wrap the attribute value like a string literal

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

    Demo: Fiddle

    0 讨论(0)
提交回复
热议问题