$('a[xlink:href=#'+value.id+']').addClass("foo");
我有一个 svg,里面有 <a xlink:href="#21" xlink:title="21"></a>
围绕多边形。
我想做的是向 a
添加一个类xlink:href
在哪里与 value.id
匹配
最佳答案
在使用双反斜杠将元字符用作选择器之前,您必须对其进行转义。
这样做:
$('a[xlink\\:href=#'+value.id+']').addClass("foo");
jQuery 文档说:
To use any of the meta-characters ( such as
!"#$%&'()*+,./:;<=>?@[\]^
{|}~` ) as a literal part of a name, it must be escaped with with two backslashes: \. For example, an element with id="foo.bar", can use the selector $("#foo\.bar").
关于javascript - jQuery 添加类到 xlink :href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23544479/