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

by Yang Yang on April 16, 2009

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.

INDK October 4, 2010 at 8:43 pm

Thanks Buddy that was helpful

Comments on this entry are closed.

Previous post:

Next post: