Remove multiple html5 data-attributes with jquery

后端 未结 7 1136
清酒与你
清酒与你 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 14:53

    Sadly it is not possible in jQuery to select attribute names that starts with a given value (for attribute values it is possible).

    The easiest solution i came up with:

    $(document).ready(function(){
        $('[data-loremIpsum], [data-loremDolor]').each(function(index, value) {
            $(this).removeAttr('data-loremIpsum')
                   .removeAttr('data-loremDolor');
        });
    });
    

    JsFiddle Demo (Make sure to look up the html source code after you clicked run)

提交回复
热议问题