我正在通过我的代码动态构建 anchor 标记。
str += " <li><a href='" + hyperlink + "'>" + linkName + "</a></li>";
我想在特定条件下将以下样式应用于此 anchor 标记。
style="pointer-events: none;cursor: default;"
If (somecond) { apply the above style to anchor tag }
请建议如何实现这一目标。
提前致谢。
最佳答案
使用 jquery .css()
函数(see docs),例如:
if(somecond) {
$('a').css({
"pointer-events": "none",
"cursor": "default"
});;
}
关于jQuery代码动态添加样式到 anchor 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29362005/