Escape square brackets when assigning a class name to an element

后端 未结 4 1612
你的背包
你的背包 2020-12-09 01:05

Does anyone know how to escape the square bracket character when setting a class name with jQuery?

Try the following:

$(\'#txtFirstname\').addClass(\         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-09 01:50

    The introduction of jQuery API page gives the above explanation about this:

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

提交回复
热议问题