.removeAttr() JQ Home  <<  A & P  <<  .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 ) Example A & P  <<  Top

Remove one or more attributes from each element within the matched set.

In the example below when 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:

Related Tutorials

jQuery Basic Tutorials - Lesson 9 - Working With CSS Attributes