Remove IMG height and width attributes with jQuery

You’ll sometimes want to remove the height and width attributes from an image tag. You’ll come across this a lot while working with WordPress content, in which case embeded images are given height and width attributes. A simple one liner of jQuery will allow you to remove the height and width from IMG tags:

$(“img”).removeAttr(“height width”);

Of course the line above will remove height and width from ALL images within your document. You’ll want to better specify the image by including it’s parent container or class.

jQuery’s “removeAttr” will come in handy for other things such as iframes, etc..

Resources

 

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply