5 Hours

With jQuery, how can I select an element with a metacharacter in its name?

Say I have custom HTML tags:

<fb:est hours="5">5 Hours</fb:est> <fb:act hours="4">4 Hours</fb:act> 

How to select fb:est elements?

Doing var e = $('fb:est') does not work. And var e = $('fb\:est') doesn't work either.

+4
source share
1 answer

From jQuery docs :

If you want to use any of the metacharacters (#; &, + * ~ ': "! ^ $ => | / @) As the literal part of the name, you should avoid the double backslash character: \. For example, if you have an input with the names name = "[]", you can use the $ selector ("Login [name = names \ [\]]").

So this is the way to do this:

var e = $('fb\\:est')

+9
source

All Articles