Remove multiple html5 data-attributes with jquery

后端 未结 7 1130
清酒与你
清酒与你 2020-12-16 14:25

So jquery api says the following:

Removing data from jQuery\'s internal .data() cache does not effect any HTML5 data- attributes in a document; use .

相关标签:
7条回答
  • 2020-12-16 15:05
    // Fetch an array of all the data
    var data = $("a").data(),
        i;
    // Fetch all the key-names
    var keys = $.map(data , function(value, key) { return key; });
    // Loop through the keys, remove the attribute if the key contains "lorem".
    for(i = 0; i < keys.length; i++) {
        if (keys[i].indexOf('lorem') != -1) {
            $("a").removeAttr("data-" + keys[i]);
        }
    }
    

    Fiddle here: http://jsfiddle.net/Gpqh5/

    0 讨论(0)
提交回复
热议问题