javascript - jQuery 属性选择器 : How to query for an attribute with a custom namespace

标签 javascript jquery

假设我有一个简单的 XHTML 文档,它为属性使用自定义命名空间:

<html xmlns="..." xmlns:custom="http://www.example.com/ns">
    ...
    <div class="foo" custom:attr="bla"/>
    ...
</html>

如何使用 jQuery 匹配具有特定自定义属性的每个元素?使用

$("div[custom:attr]")

不起作用。 (到目前为止,仅尝试使用 Firefox。)

最佳答案

jQuery不直接支持自定义命名空间,但是可以通过过滤功能找到你要找的div。

// find all divs that have custom:attr
$('div').filter(function() { return $(this).attr('custom:attr'); }).each(function() {
  // matched a div with custom::attr
  $(this).html('I was found.');
});

关于javascript - jQuery 属性选择器 : How to query for an attribute with a custom namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/91518/

相关文章:

javascript - 关注文本区域到最后+1个字符光标,javascript

javascript - Uncaught ReferenceError : function is not defined at HTMLButtonElement. onclick

javascript - Ajax onSuccess 回调,但无法控制 ajax 调用

jquery - 如何计算渲染部分中的循环?

javascript - CSS3变换后获取div的实际像素坐标

jquery - 在 jQuery 中重复调整窗口大小的函数

javascript - 将 javascript 值推送到 php

javascript - 自动 Firefox 单击出现的按钮

javascript - 文本区域中的滚动条光标模式(适用于谷歌浏览器)

javascript - Kendo 自动完成多个关键字