In this post, we will learn how to remove attribute from an element in jQuery. So how we can do this, we will learn in this post. 


How To Remove Attribute From An Element In jQuery ?


Remove Attribute From An Element

To remove attribute from an element, we use   removeAttr()  jQuery method. In this given example when we click on the button then the  placeholder  attribute removed. So how this works we will see in the given example.


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How To Remove Attribute From An Element In jQuery ?</title>
</head>
<body>

<input type="text" placeholder="Type your text...">
<br/><br/>
<button type="button">Remove Attribute</button>

<!-- jQuery CDN -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>


<script>

$(document).ready(function(){
$("button").click(function(){
$('input[type="text"]').removeAttr("placeholder");
});
});

</script>
</body>
</html> code-box



Summary

In this post we learned how to remove attribute from an element in jQuery. You try to make it yourself. I hope you make. If you face any problem, then comment and tell us. Keep visiting the blog to read more similar posts. 

Post a Comment

Previous Post Next Post