.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 DOM removeAttribute() method. Because it is called directly on a jQuery 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
attributeNameA 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 For Testing The .removeAttr( attributeName ) Signature
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');
  });
});

Press the button below to action the above code: