How to remove data- attribute from the div element?
javascript, jquery
Solution
No, you have to loop through them and remove them individually. E.g.:
var $div = $("selector for the div"),
attrs = $div[0].attributes,
name,
index;
for (index = attrs.length - 1; index >= 0; --index) {
name = attrs[index].nodeName;
if (name.substring(0, 5) === "data-") {
$div.removeAttr(name);
}
}
Live copy | source
...or something along those lines.
Problem
I have an html `div` element, which contains lot of HTML-5 `data-` attributes to store extra data with element. I know that we can use `removeAttr` of jquery to remove specific attribute, but i want to know that is there any way to remove `data-` all atonce?