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.


<!DOCTYPE html>



<title>Jquery Set Attribute Value Example-nicesnippets.com</title>


<style type="text/css">







<button>Set Attribute</button>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>



$("h1").attr("class", "design");

$("button").attr("disabled", "disabled");





It will help you...