Remove multiple attributes with jQuery's removeAttr

Jquery

Jquery Problem Overview


I have the following code.

$(document).ready(function(){
 $('#listing img')
 .attr('width', 250)
 .removeAttr('height').removeAttr('align').removeAttr('style')
 .wrap('<p />');
});

Is there a more efficient way of removing multiple attributes?

Jquery Solutions


Solution 1 - Jquery

Yes :

.removeAttr('height align style')

From the documentation :

> as of version 1.7, it can be a space-separated list of attributes.

Solution 2 - Jquery

Yes, you can remove it in that way:

$('#listing img').removeAttr('height align style');

you can also add those attributes as follows:

$('#listing img').attr({ height: "20", align: left }).css({ color: red, text-align: center });

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsomecallmejoshView Question on Stackoverflow
Solution 1 - JqueryDenys SéguretView Answer on Stackoverflow
Solution 2 - JqueryPritam Jyoti RayView Answer on Stackoverflow