jQuery .removeAttr() removes an attribute from each element in the set of matched elements
Syntax and description
.removeAttr
removes an attribute from
each element in the set of matched elements.
It has two forms:
.removeAttr(attributeName)
attributeName: An attribute to remove.removeAttr(function)
function: A function returning the attribute to remove
Its return value is the jQuery object, for chaining purposes.
The following code example shows .removeAttr() in action, removing the class attribute from the #myID div.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.blue {<!-- w ww . j a va 2 s .c om-->
background-color: blue;
}
</style>
<script src="http://java2s.com/style/jquery-1.8.0.min.js">
</script>
<script>
$(function(){
$("p#myID").removeAttr("class");
});
</script>
</head>
<body>
<p id="myID" class="blue" >
This is a test. java2s.com
</p>
</body>
</html>
Remove with a function
The .removeAttr()
function allows us to indicate
the attribute to be removed by passing in a function.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w w w . j a v a2 s. co m-->
$("input").removeAttr("disabled").focus().val("editable now");
});
</script>
</head>
<body>
<body>
<button>Enable</button>
<input type="text" disabled="disabled" value="data"/>
</body>
</html>