Categories
JavaScript Tips & Tutorials jQuery Tips & FAQ

jQuery: Selecting elements with uncommon / special characters in ID or class name

HTML generated by some CMS or frameworks include elements with rather uncommon characters in ID or class names. For example, some may have special characters such as ‘.’ or ‘[..]’ in the ID or Class. To work around this, a selector in jQuery should be written this way:

$("$some.id") // won't work for ID: some.id $("$some\\.id") // works for ID: some.id

With brackets in ID:

$("$some[id]") // won't work for ID: some[id] $("$some\\[id\\]") // works for ID: some[id]

You get the idea. Just add double backslashes \\ before any of the special characters.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

One reply on “jQuery: Selecting elements with uncommon / special characters in ID or class name”

Comments are closed.