jQuery .removeAttr(): Delete HTML Attributes
.removeAttr() deletes named HTML attributes from the selected elements. Separate the names with spaces to remove several at once. Removing placeholder, for example, leaves the text already entered in the field.
Delete one or more attributes
Pass a string of attribute names, such as "placeholder title". The selector belongs in $("#name"). Use plain names as arguments to .removeAttr(). Removing a missing attribute has no effect, and the method returns the jQuery object it acted on. jQuery API — .removeAttr()
$("#name").removeAttr("placeholder");
$("#name").removeAttr("placeholder title");
Remove input hints while preserving typed text
Save the complete code in UTF-8 as jquery-removeattr.html and open it in a browser. It loads jQuery 4.0.0 from the official CDN and needs internet access. Type a name and press Remove hint attributes.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery .removeAttr() example</title>
<style>
body { margin: 24px; font: 1rem/1.6 system-ui, sans-serif; overflow-wrap: anywhere; }
label { display: block; }
button, input { font: inherit; }
input { box-sizing: border-box; max-width: 100%; border: 2px solid #a1a7ad; padding: .4rem; }
input[placeholder] { border-color: #08716d; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
</style>
<script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
</head>
<body>
<main>
<h1>jQuery .removeAttr() example</h1>
<label for="name">Name</label>
<input id="name" type="text" placeholder="Example: Alex Kim" title="Name hint">
<div class="actions">
<button id="empty" type="button">Empty the hint value</button>
<button id="remove" type="button">Remove hint attributes</button>
</div>
<p id="output" role="status"></p>
</main>
<script>
$(function () {
const $name = $("#name");
function report() {
const present = $name[0].hasAttribute("placeholder");
$("#output").text("Placeholder present: " + present +
" / " + "Current value: " + $name.val());
}
$("#empty").on("click", function () {
$name.attr("placeholder", "");
report();
});
$("#remove").on("click", function () {
$name.removeAttr("placeholder title");
report();
});
report();
});
</script>
</body>
</html>
The placeholder and title attributes disappear. The status shows false and the name you typed. The field’s label stays in place. To clear the current input value, pass an empty string to .val().
Compare an empty value with attribute removal
Reload and click Empty the hint value. It uses .attr() to set placeholder to an empty string. The hint disappears, but placeholder="" remains. The status reads true and the [placeholder] CSS rule keeps the field’s border teal.
Click Remove hint attributes next. The status becomes false and the border turns gray. Compare the attributes in the Elements panel or run document.getElementById("name").hasAttribute("placeholder").
Distinguish a checkbox’s default and current states
The HTML checked attribute sets the default checked state, while the checked property is the current state. Once the property has been set directly, deleting the attribute can leave the current state unchanged. Use .prop() to read or update the current state.
const $box = $('<input type="checkbox" checked>');
$box.prop("checked", true);
$box.removeAttr("checked");
console.log($box[0].defaultChecked, $box.prop("checked")); // false true
$box.prop("checked", false);
console.log($box.prop("checked")); // false
Run the snippet in the example console. The first output is false true. The default is now unchecked, but the current state remains checked. The last call sets the current state to false. To enable a disabled field, set its state with .prop("disabled", false).
Handle accessibility attributes and event listeners
A button that controls a disclosure uses aria-expanded="false" when the panel is collapsed. Deleting the attribute does not communicate that state in the same way. Set the accessibility attribute in step with the actual visibility of the controlled content. WAI-ARIA APG — Disclosure Pattern
Deleting an inline onclick attribute leaves listeners registered through .on() in place. Use .off() with the matching event and handler or namespace to remove those listeners.




