jQuery removeAttr()

Introduction

Remove the style attribute from all <p> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>// w ww .  ja  v  a2 s.  c o  m
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").removeAttr("style");
  });
});
</script>
</head>
<body>

<h1>This is a heading</h1>

<p style="font-size:120%;color:red">This is a paragraph.</p>
<p style="font-weight:bold;color:blue">This is another paragraph.</p>

<button>Remove the style attribute from all p elements</button>

</body>
</html>

The removeAttr() method removes one or more attributes from the selected elements.

$(selector).removeAttr(attribute)
Parameter
Optional
Description
attribute

Required.

one or more attributes to remove.
To remove several attributes, separate the attribute names with a space



PreviousNext

Related