.removeAttr()
S2C Home « Attributes & Properties « .removeAttr()
Attribute removal.
Description
The .removeAttr()
method is used to remove one or more attributes from each element within the matched set.
- Under the covers the
.removeAttr()
method uses the DOMremoveAttribute()
method. Because it is called directly on ajQuery
object, it has the advantage of accounting for different attribute naming across browsers. - When removing an inline
onclick
event the desired results are not achieved in IE6-8, so use the.prop()
method for this.
Syntax
Signature | Description |
---|---|
.removeAttr( attributeName ) | Remove one or more attributes from each element within the matched set. |
Parameters
Parameter | Description | Type |
---|---|---|
attributeName | A space-separated list of attributes. | String |
Return
A jQuery
object.
.removeAttr( attributeName )
ExampleTop
Remove one or more attributes from each element within the matched set.
In the example below we remove the class and id attributes from each 'td' element, thus removing the background colour styling.
Table Row 1, Table Data 1 Class of turnOrange | Table Row 1, Table Data 2 ID of id1 |
Table Row 2, Table Data 1 Class of turnOlive | Table Row 2, Table Data 2 ID of id1 |
Table Row 3, Table Data 1 | Table Row 3, Table Data 2 |
$(function(){
$('#btn8').on('click', function() {
$('#table1 td').removeAttr('class id');
});
});
Related Tutorials
jQuery Basic Tutorials - Lesson 9 - Working With CSS Attributes