jQuery add attribute to an HTML elements using jQuery attr() method. However, you can use this method to add attributes as well as the value of the relevant attribute.

If you want to learn more about the jQuery attr method, you have to visit jQuery attr() method page to learn the syntax and learn it in more details.

How jQuery Add Attribute to an HTML element

See the below given example to learn the method and add attribute.
Add Class Attribute

Output


This is the answer to add attributes to an HTML element using jQuery attr() method.

The above example adds a class attribute to the HTML paragraph tag. The method adds the class attribute to the HTML element as well the styling of the specified class.

Click the Add attribute button to see the changes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.