How to select html nodes by ID with jquery when the id contains a dot?

后端 未结 8 1056
生来不讨喜
生来不讨喜 2020-11-22 08:22

If my html looked like this:


    

        
8条回答
  •  一向
    一向 (楼主)
    2020-11-22 08:31

    Guys who's looking for more generic solution, I found one solution which inserts one backward slashes before any special characters, this resolves issues related to retrieving name & ID from a div which contains special characters.

    "Str1.str2%str3".replace(/[^\w\s]/gi, '\\$&')

    returns "Str1\\.str2\\%str3"

    Hope this is useful !

提交回复
热议问题