To get or set a particular attribute of an element,
attr() method can be used.
In above code snippet, the first line of code will set the
class attribute as “class2” of the div element whose id as “div2”. The second line of code will show alert with the value of class attribute for the element whose id is “div2”.