Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery get Custom attributes

Shulou Source: shulou.com Published: 2022-05-31 16:47:59 09月21日 Update

In this article Xiaobian for you to introduce in detail "jquery how to get custom attributes", the content is detailed, the steps are clear, the details are handled properly, I hope this "jquery how to get custom attributes" article can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge.

Jquery can get custom attributes; you can use the attr () method to get custom attributes, which are used to set or return the property values of the selected element, including custom attributes. When only the attribute to be obtained is specified in the parameter, the specified attribute value is returned with the syntax of "element object .attr (custom attribute)".

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

Can jquery get custom attributes?

The attr () method sets or returns the property value of the selected element.

The working mode of the method is also different according to the different parameters of the method.

Returns the attribute value of the selected element.

Grammar

$(selector) .attr (attribute)

The attribute specifies the attribute whose value you want to get.

Examples are as follows:

Get property-attr ()

Value of jquery:

$("# tiny") .attr ("value")

Get custom properties

Value of jquery:

$("# tiny") .attr ("data_obj")

Examples are as follows:

$(document) .ready (function () {$("button") .click (function () {alert ($("img"). Attr ("city"));})

Returns the width of the image

Output result:

After clicking the button:

After reading this, the article "how to get custom attributes in jquery" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Attributes elements methods articles content parameters examples syntax differences appropriateness images widths objects differences ideas buttons tutorials new knowledge ways more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple OPPO Reno Microsoft vpn