Jquery Set Attribute Value Example
Hi Guys
In this blog, I will explain how to jquery set attribute value. we are showing a full example of set attribute value using jquery For setting attributes we pass two parameters, name and value in the attr() method. This will set all elements with the named attribute using the value passed by the method.
jQuery set attribute syntax: attr(name, value) – name could be any html attribute.
In below example the value of the ‘alt’ is set using the attr(name, value) method.
Example
<!DOCTYPE html>
<html>
<head>
<title>Jquery Set Attribute Value Example-nicesnippets.com</title>
</head>
<style type="text/css">
.design{
color:red;
}
</style>
<body>
<h1>Nicesnippets.com</h1>
<button>Set Attribute</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
<script>
$(document).ready(function(){
$("h1").attr("class", "design");
$("button").attr("disabled", "disabled");
});
</script>
</body>
</html>
It will help you...
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get Current Page URL, Path, Host and hash using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- JQuery Remove All Unwanted Whitespace From String Example
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example