javascript - jQuery 添加类到 xlink :href

标签 javascript jquery addclass

$('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/

相关文章:

javascript - 运行小部件时是否需要开源的 kendo.core.js?

javascript - addClass - 一个函数而不是 3 个函数(缩短代码)

javascript - 执行 .click(function() 只有第一次点击

javascript - 如何使用 jQuery 检测两次快速点击并更改两者的 Action

javascript - 将鼠标悬停在 div 上可以平滑地更改背景

javascript - 如何理解javascript中的全局变量和局部变量

javascript - 将值解析为 javascript 函数

javascript - jQuery - 使用 inArray() 查找 jQuery 对象的索引

javascript - 随机报价机 - 使用 jQuery 单击更改颜色

javascript - 不稳定悬停时菜单和子菜单的行为不符合预期