Monday, 4 February 2013

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

 
Just add double backslashes \\ before any of the special characters 
 
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:
 
Example 1 
 
$("$title.id") // won't work for ID: title.id
 
$("$title\\.id") // works for ID: title.id  
 
 
Example 2
$("$title[id]") // won't work for ID: title[id]

$("$title\\[id\\]") // works for ID: title[id]
 

No comments:

Post a Comment