Rob Sobers
Rob Sobers

Reputation: 21125

With jQuery, how do I select an element with a meta-character in its name?

Let's say I have custom HTML tags like so:

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

How do I select the fb:est elements?

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

Upvotes: 4

Views: 299

Answers (1)

Rob Sobers
Rob Sobers

Reputation: 21125

From the jQuery docs:

If you wish to use any of the meta-characters (#;&,.+*~':"!^$=>|/@ ) as a literal part of a name, you must escape the character with two backslashes: \. For example, if you have an an input with name="names[]", you can use the selector $("input[name=names\[\]]").

So, this is the way to do it:

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

Upvotes: 9

Related Questions