In this tutorial, We will learn how to jquery set attribute values. We set attribute value using jquery use attr() method. 


Example:

<!DOCTYPE html>
<html>
    <head>
        <title>Jquery Set Attribute Value</title>
    </head>
    <style type="text/css">
        .design{
            color:red;
        }
    </style>
    <body>
        <h1>Some test</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");

                 //set element attribute 
                $("button").attr("disabled", "disabled");
            });
        </script>
    </body>
</html>


Thanks, May this example will help you.




Are you facing problems in understanding this article?
You can watch the video. Watch it now