jQuery

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 Attributes

Attributes

 

 

We can easily manipulate all the attributes given to an element with the help of jQuery. These attributes can be src, href, id, class, style, width, height, and many more.

The only method used for this purpose is attr(). This method can be used to either get the attribute value or it can be used to set the attribute value. IN other words, it can perform both actions i.e, get attribute value and set the attribute value.

 

Syntax:-

 

  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 Basic

All Sections related to jQuery