Home>Article>Web Front-end> Can jquery add new attributes to elements?

Can jquery add new attributes to elements?

WBOY
WBOY Original
2022-06-17 16:35:10 1745browse

jquery can add new attributes to elements; jquery can use the attr() method to add new attributes to elements. This method is used to set or return the attributes and values of the specified element. The first parameter in brackets is set For a newly added attribute, just set the second parameter to the value of the new attribute, and the syntax is "$(selector).attr(attribute,value)".

Can jquery add new attributes to elements?

The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.

Can jquery add new attributes to elements

jquery can add new attributes to elements

attr() method sets or returns the attribute of the selected element Properties and values.

When this method is used to return an attribute value, the value of the first matching element is returned.

When this method is used to set attribute values, one or more attribute/value pairs are set for the matching element.

Syntax

Return the value of the attribute:

$(selector).attr(attribute)

Set the attribute and value:

$(selector).attr(attribute,value)

The example is as follows:

    123   
Pulpit Rock

Output result:

Can jquery add new attributes to elements?

Video tutorial recommendation:jQuery video tutorial

The above is the detailed content of Can jquery add new attributes to elements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn