仅按属性选择元素

时间:2012-05-30 10:03:40

标签: javascript jquery

  

可能重复:
  JQuery, is there a way to select all elements on the page with a specific attribute?

我的代码

<html>
    <body>
        <script>
            $(function(){
                $("No idea what to write here").remove();
            });
        </script>

        <button data-fun="a">Remove</button>
        <div data-fun="b">Remoave</div>
        <span data-fun="c">Remdove</span>
        <strong data-fun="d">Rdemove</strong>
        <b data-fun="e">Remosve</b>
        <p data-fun="f">Remoe</p>
        <div>Not Remove</div>
    </body>
</html>

我想删除所有具有data-fun属性的元素,无论元素是什么,data-fun的值是什么。

2 个答案:

答案 0 :(得分:4)

你可以试试这个:

$(function() {
     $("[data-fun]").remove();
})

<强> Working sample

答案 1 :(得分:0)

演示 http://jsfiddle.net/JfBvG/

<强>码

$(function(){
$("[data-fun]").remove();
});​