开发者

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

Let's say 开发者_如何学PythonI 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.


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')

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜