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
- How to Center a Popup Window on Screen
- How to hide URL in the popup window opened using window.open
- window.showModalDialog is deprecated in Edge and Chrome
- Cloning JavaScript Object with Object.create
- Set new Attribute in XML using jQuery
- DOMParser: parseFromString() method
- What is the use of attr() method in jQuery?
- What is jQuery CDN?
- Difference between $(this) and ‘this’ in jQuery
- jQuery important questions
- Checkbox validation in jQuery
- Difference between offset and position in jQuery?
- How to change the background image using jQuery?
- jQuery Methods
- jQuery Selectors
- jQuery Downloading
- jQuery History