For example, to conceive such code $('div, ul, ol, p').removeAttr('class, align, width');
would remove from all listed tags all listed attributes, if any. This code only works one by one, like this $('div').removeAttr('class');
but it does not fit.
|
1 answer
https://api.jquery.com/removeAttr/
... as of version 1.7, it can be a space-separated list of attributes.
... from version 1.7 it can have several attribute names separated by spaces.
$('div, ul, ol, p').removeAttr('class align width');
console.log("before:", $("div")[0].outerHTML); console.log("before:", $("p")[0].outerHTML); $('div, ul, ol, p').removeAttr('class align width'); console.log("after:", $("div")[0].outerHTML); console.log("after:", $("p")[0].outerHTML);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="aaa" width="200px"></div> <p title="test" class="bbb"></p>
|