jQuery Intro

jQuery Intro Quiz

jQuery Intro Exercise

jQuery Basic

jQuery Basic Quiz

jQuery Basic Exercise

jQuery Advance

jQuery Advance Quiz

jQuery Advance Exercise

jQuery Selectors

jQuery Effects

jQuery Events

jQuery Methods and Properties

jQuery Traversing

jQuery CSS and HTML Methods

jQuery attr() Method

jQuery attr() Method



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




  1. Its syntax for getting attribute value is:- $(selector).attr(attribute)
  2. Its syntax for setting attribute value is:- $(selector).attr(attribute,value)
  3. For setting attribute value with a function, its syntax is:- $(selector).attr(attribute,function(index,currentvalue))
  4. For setting multiple attributes and values, its syntax is:- $(selector).attr({attribute:value, attribute:value,...})


Further Explanation:-


Parameter Description
attribute Specifies the name of the attribute
value Specifies the value of the attribute
function(index,currentvalue) Specifies a function that returns the attribute value to set
  • index - Receives the index position of the element in the set
  • currentvalue - Receives the current attribute value of selected elements

Code Explanation

All Tutorials related to jQuery CSS and HTML Methods

All Sections related to Jquery