jQuery .removeAttr() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Attribute methods

What You’ll Learn

The .removeAttr() method removes HTML attributes from matched elements. This tutorial covers the single- and multi-attribute API (space-separated since 1.7), equivalence with .attr(name, null), comparisons with .removeProp() and .removeClass(), the IE onclick caveat, and five official and practical jQuery demos.

01

Remove one

Single attribute

02

Remove many

Space-separated

03

All matches

Every element

04

vs .attr(null)

Same effect

05

IE onclick

Use .prop()

06

Since 1.0

Core API

Introduction

HTML attributes decorate elements in markup — title for tooltips, alt on images, required on form fields, and aria-* for accessibility. When JavaScript needs to strip those attributes at runtime, jQuery provides .removeAttr().

Available since jQuery 1.0, .removeAttr() wraps the native removeAttribute() function with two key advantages: it operates on a jQuery collection (removing from every matched element) and it accounts for inconsistent attribute naming across browsers. Since jQuery 1.7, a single call can remove multiple attributes by passing a space-separated list.

Removing an attribute is equivalent to calling .attr(name, null). For live DOM properties — especially inline event handlers like onclick in older Internet Explorer — reach for .prop(name, null) instead.

Understanding the .removeAttr() Method

Given a jQuery object representing one or more DOM elements, .removeAttr(attributeName) removes the named attribute from each element in the set. The method returns the original jQuery object for chaining — for example, $("input").removeAttr("title").addClass("clean").

Attributes live in HTML markup; properties are live DOM state. Removing an attribute does not always reset the corresponding property — the IE onclick case is the most common pitfall. For CSS classes, prefer .removeClass() over stripping the entire class attribute unless you need to remove the attribute itself.

💡
Beginner Tip

$("input").removeAttr("title") removes the title attribute from every matched input. After removal, .attr("title") returns undefined — hover tooltips disappear because the attribute no longer exists in markup.

📝 Syntax

jQuery .removeAttr() accepts one argument form:

Remove attribute(s) — since 1.0 (multi-name since 1.7)

jQuery
.removeAttr( attributeName )
  • attributeName — a single attribute name, or since jQuery 1.7 a space-separated list of attributes to remove.
  • Removes the attribute from every matched element.
  • Returns the original jQuery object (for chaining).

Return value

  • Always returns the original jQuery object — enabling method chaining.

Equivalent removal with .attr()

Passing null as the value to .attr() removes the attribute the same way:

jQuery
// These are equivalent
$("div").removeAttr("title");
$("div").attr("title", null);

WARNING: inline onclick in IE

Removing an inline onclick handler with .removeAttr() does not work reliably in Internet Explorer 8, 9, and 11. Use .prop() instead:

jQuery
// Correct — clears the live onclick property
$element.prop("onclick", null);
console.log("onclick property: ", $element[0].onclick);



// Unreliable in IE 8, 9, 11
// $element.removeAttr("onclick");

Official jQuery API example

jQuery
var inputTitle = $( "input" ).attr( "title" );
$( "button" ).on( "click", function() {
  var input = $( this ).next();
  if ( input.attr( "title" ) === inputTitle ) {
    input.removeAttr( "title" );
  } else {
    input.attr( "title", inputTitle );
  }
  $( "#log" ).html( "input title is now " + input.attr( "title" ) );
});

⚡ Quick Reference

GoalCode
Remove one attribute$("input").removeAttr("title")
Remove multiple attributes (1.7+)$("div").removeAttr("title data-role data-version")
Same via .attr()$("img").attr("alt", null)
Clear validation attrs$("input").removeAttr("aria-invalid required")
Remove CSS class (prefer)$("div").removeClass("active") — not .removeAttr('class')
Clear inline onclick (IE-safe)$("button").prop("onclick", null)

📋 .removeAttr() vs .attr(null) vs .removeProp() vs .removeClass()

Four ways to strip information from elements — pick the right layer.

.removeAttr()
- HTML attr

Remove markup attributes — title, alt, required, data-*

.attr(null)
same effect

Equivalent removal via .attr(name, null)

.removeProp()
- jQ prop

Remove jQuery-added properties only — not native DOM props

.removeClass()
- CSS class

Strip CSS classes — prefer over .removeAttr('class')

Examples Gallery

Examples 1–5 follow the official jQuery API documentation and practical patterns. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demo for toggling attributes on and off.

Example 1 — Official Demo: Toggle title on an Input

Click the button to add or remove the title attribute — hover the input to see the tooltip appear and disappear.

jQuery
var inputTitle = $( "input" ).attr( "title" );
$( "button" ).on( "click", function() {
  var input = $( this ).next();
  if ( input.attr( "title" ) === inputTitle ) {
    input.removeAttr( "title" );
  } else {
    input.attr( "title", inputTitle );
  }
  $( "#log" ).html( "input title is now " + input.attr( "title" ) );
});
Try It Yourself

How It Works

The code stores the original title value, then toggles between .removeAttr("title") and .attr("title", inputTitle). After removal, .attr("title") returns undefined.

Example 2 — Remove Multiple Attributes (Space-Separated, 1.7+)

Pass a space-separated list to strip title, data-role, and data-version in one call.

jQuery
$( "#box" ).removeAttr( "title data-role data-version" );
$( "#log" ).html(
  "title: " + $( "#box" ).attr( "title" ) + "<br>" +
  "data-role: " + $( "#box" ).attr( "data-role" ) + "<br>" +
  "data-version: " + $( "#box" ).attr( "data-version" )
);
Try It Yourself

How It Works

Since jQuery 1.7, a single string with space-separated attribute names removes each one from every matched element. This is cleaner than three separate .removeAttr() calls.

📈 Practical Patterns

Equivalence, validation cleanup, and IE-safe event handler removal.

Example 3 — Equivalent to .attr(name, null)

Compare .removeAttr('alt') with .attr('title', null) — both delete attributes from markup.

jQuery
$( "#pic" ).removeAttr( "alt" );
// Same effect as:
$( "#pic" ).attr( "title", null );
Try It Yourself

How It Works

jQuery treats null as a removal signal in .attr(). Choose .removeAttr() when removal is the explicit intent; use .attr(name, null) when you already use .attr() for get/set in the same function.

Example 4 — Remove aria-invalid and required After Validation

Strip validation-related attributes once the user provides valid input.

jQuery
var $el = $( "#email" );
$el.addClass( "ok" ).removeAttr( "aria-invalid required" );
$( "#msg" ).text(
  "Removed aria-invalid and required — attrs: " + $el[ 0 ].attributes.length
);
Try It Yourself

How It Works

Removing required stops HTML5 constraint validation on submit. Removing aria-invalid clears the accessibility error state. Chain .addClass() before .removeAttr() for a single fluent call.

Example 5 — Clear Inline onclick With .prop(), Not .removeAttr()

Internet Explorer 8, 9, and 11 ignore .removeAttr('onclick') — use .prop('onclick', null) instead.

jQuery
$( ".demo" ).prop( "onclick", null );
console.log( "onclick property: ", $( ".demo" )[ 0 ].onclick );
// Unreliable in IE 8, 9, 11:
// $( ".demo" ).removeAttr( "onclick" );
Try It Yourself

How It Works

Inline event handlers are live DOM properties, not just markup attributes. Setting the property to null via .prop() clears the handler reliably across browsers including legacy IE.

🚀 Common Use Cases

  • Toggle tooltips$("input").removeAttr("title") to hide hover text after the user dismisses a hint.
  • Lazy-load cleanup$("img").removeAttr("data-src") after copying the URL into src.
  • Form validation reset$("input").removeAttr("aria-invalid required") when input becomes valid.
  • Strip deprecated data attrs$(".widget").removeAttr("data-version data-role") after migration.
  • Disable link navigation$("a.disabled").removeAttr("href") to prevent clicks without removing the element.
  • Accessibility cleanup$("[aria-hidden]").removeAttr("aria-hidden") when content becomes visible.

🧠 How .removeAttr() Removes Attributes

1

Match elements

jQuery object holds one or more DOM nodes.

Input
2

Parse attribute names

Single name or space-separated list (since 1.7).

Args
3

Call removeAttribute()

jQuery normalizes naming and removes from each element.

DOM
4

jQuery object returned

Attribute gone from every match — chain further methods freely.

📝 Notes

  • Available since jQuery 1.0 — space-separated multi-attribute removal since 1.7.
  • Removes attributes from every matched element; returns the jQuery object for chaining.
  • Equivalent to .attr(name, null) for attribute removal.
  • Uses native removeAttribute() with cross-browser attribute name normalization.
  • .removeAttr('onclick') is unreliable in IE 8, 9, and 11 — use .prop('onclick', null).
  • Do not use .removeProp() on native DOM properties — it is for jQuery-added properties only.
  • Prefer .removeClass() over .removeAttr('class') for CSS class manipulation.

Browser Support

.removeAttr() has been part of jQuery since 1.0+. Multi-attribute removal via a space-separated string arrived in 1.7+. jQuery normalizes cross-browser attribute naming — the main reason to prefer it over raw removeAttribute() in legacy projects.

jQuery 1.0+

jQuery .removeAttr()

Supported in jQuery 1.x, 2.x, 3.x, and 4.x across all modern browsers and IE with supported jQuery builds. Native equivalent: element.removeAttribute() — jQuery adds collection semantics, multi-name removal, and cross-browser normalization. Exception: inline onclick removal in IE requires .prop('onclick', null).

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.removeAttr() Universal

Bottom line: Safe in any jQuery project. Use .removeAttr() for HTML attributes; .prop(null) for inline event handlers in IE.

Conclusion

The jQuery .removeAttr() method removes HTML attributes from every matched element. It is the dedicated removal API — cleaner than .attr(name, null) when stripping attributes is the sole goal, and it supports removing multiple attributes in one call since jQuery 1.7.

Remember the official demo: toggle a title attribute on an input with .removeAttr("title") and .attr("title", value). For inline onclick handlers in legacy IE, use .prop("onclick", null) instead. Chain freely — .removeAttr("data-old").addClass("migrated").

💡 Best Practices

✅ Do

  • Use .removeAttr() when removal is the explicit intent
  • Pass space-separated names to remove multiple attributes at once (1.7+)
  • Use .prop('onclick', null) to clear inline event handlers in IE
  • Use .removeClass() for CSS class changes instead of stripping class
  • Chain after removal — .removeAttr('title').addClass('clean')

❌ Don’t

  • Use .removeAttr('onclick') expecting it to work in IE 8, 9, or 11
  • Call .removeProp() on native DOM properties like checked
  • Use .removeAttr('class') when .removeClass() is sufficient
  • Assume removing an attribute resets the corresponding live property
  • Remove required without also updating visual validation state

Key Takeaways

Knowledge Unlocked

Five things to remember about .removeAttr()

Strip markup attributes — not live properties.

5
Core concepts
-N 02

Many attrs

Since 1.7

API
null 03

= .attr(null)

Equivalent

Compare
all 04

Every match

Not first only

Behavior
.prop 05

IE onclick

Use .prop()

Caveat

❓ Frequently Asked Questions

.removeAttr() removes one or more HTML attributes from every matched element. It calls the native removeAttribute() function under the hood but works on a jQuery collection and normalizes attribute naming across browsers. Available since jQuery 1.0.
They are equivalent for removal. .removeAttr('title') and .attr('title', null) both delete the title attribute from every matched element. Use .removeAttr() when removal is the sole intent, or .attr(name, null) when you already use .attr() for get/set in the same block.
Yes. Since jQuery 1.7, pass a space-separated list: .removeAttr('title data-role data-version'). jQuery removes each named attribute from every element in the matched set in one call.
Yes. Unlike .attr() getters (which read the first element only), .removeAttr() is a setter-style operation that removes the attribute from every element in the jQuery collection and returns the same jQuery object for chaining.
Removing an inline onclick event handler with .removeAttr() does not achieve the desired effect in IE 8, 9, and 11. Use .prop('onclick', null) instead to clear the live onclick property. See Example 5 and the .prop() tutorial for details.
Prefer .removeClass() for CSS class manipulation because it handles multiple classes, partial removal, and avoids quoting the reserved word class. Use .removeAttr('class') only when you need to strip the entire class attribute from markup entirely.
Did you know?

Before jQuery 1.7, removing multiple attributes required separate .removeAttr() calls — one per attribute. The space-separated list feature mirrors a similar convenience in CSS selectors and reduces boilerplate when cleaning up data-* attributes after a widget initializes. The equivalence with .attr(name, null) exists because jQuery’s attribute module treats null as a deletion signal in both the setter and the dedicated removal method.

Next: jQuery .removeProp() Method

Remove jQuery-added properties set with .prop() — the cleanup counterpart to custom property assignment.

.removeProp() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful