How to Set Attribute Value in Jquery Example ?

Today now in this blog, I will explain you how to set attribute value by using jquery. Here i will showing a full example of set attribute value by using jquery. For setting attributes we need to pass two parameters, one is name and another one is value in the attr() method. So this will set all elements with the named attribute by using the value passed by the method.

So in jQuery set attribute syntax: attr(name, value) – So name could be any html attribute.

Now here in the below example the value of the ‘alt’ is set by using the attr(name, value) method.

<!DOCTYPE html>
  <title>Jquery Set Attribute Value</title>
<style type="text/css">
 <button>Set Attribute</button>
 <script src=""></script>
       $("h1").attr("class", "design");
       $("button").attr("disabled", "disabled");

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →