attr

UK ['ətr] US ['ətr]

abbr.attractive attractive, charming

jquery attr() method syntax

Function:attr() method sets or returns the attribute value of the selected element. Depending on the parameters of the method, the way it works is also different.

Return attribute value:Return the attribute value of the selected element.

Syntax:$(selector).attr(attribute

##Parameters:

Parameter Description attribute Specifies the attribute whose value is to be obtained.

Set attributes/values:Set the attributes and values of the selected element.

Syntax:$(selector).attr(attribute, value

Parameters:

Parameter Description attribute Specifies the name of the attribute. value Specifies the value of the attribute.

Use functions to set attributes/values:Set the attributes and values of the selected elements.

Syntax:$(selector).attr(attribute,function (index,oldvalue))

Parameters:

##Parameters attribute function(index,oldvalue)
Description
Specifies the name of the attribute.
Specifies the function that returns the attribute value . This function can receive and use the index value of the selector and the current attribute value.
Set multiple attribute/value pairs:

is the selected element Set more than one attribute and value.

Syntax:

$(selector).attr({attribute:value, attribute:value ...})

Parameters:

jquery attr() method example

    

Run instance »

Click the "Run instance" button to view the online instance

About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
Parameters attribute:value
Description
Specify one or more attribute/value pairs.