If my html looked like this:
-
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 !
- 热议问题