What is the use of attr() method in jQuery?

The attr() method sets or returns attributes and values of the selected elements. When this method is used to return the attribute value, it returns the value of theof the first matched element. When this method is used to set attribute values, it sets one or more attribute/value pairs for the set of matched elements.

$(selector).attr(attribute);           //it will return the value of an attribute.

$(selector).attr(attribute,value);     //it will set the value of an attribute.

$(selector).attr({attribute:value, attribute:value,...})      //for set multiple attribute.

More on jQuery

Leave a Reply

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