← Back to Index

.removeAttr()

Remove an attribute from each element in the set of matched elements.

Examples

1. Remove single attribute

// <a href="#" target="_blank">Link</a>
$('a').removeAttr('target');

Result

<a href="#">Link</a>

2. Remove multiple

// <img src="..." width="100" height="100">
$('img').removeAttr('width height');

Result

<img src="...">

3. Remove using function

$('a').removeAttr(function(index, el) {
     // 'this' and 'el' refer to the same DOM element
     return el.id === 'special' ? 'target' : 'href';
});

Result

// Removes 'target' from links with id="special"
// Removes 'href' from all other links

Parameters

Parameter Type Description
name string | function A string (space-separated) of attributes to remove, or a function that returns such a string. The function is called for each element with arguments (index, element).

Returns: The original SR object for chaining.