Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of attr in jquery

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge of what the concept of attr is in jquery. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

In jquery, attr full name "attribute", meaning "attribute", is an attribute operation method, can return the attribute value of the element, syntax "element .attr (" attribute name ")"; you can also set one or more attribute / value pairs for the element, syntax "element .attr ({attribute: value, attribute: value.})".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, attr's full name is "attribute", which means "attribute" in Chinese.

Attr () is a property manipulation method in jquery that sets or returns the properties and values of the selected element.

When the method is used to return a property value, it returns the value of the first matching element.

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

Syntax:

Returns the value of the property:

$(selector) .attr ("property name")

Set properties and values:

/ / set a single property and value: $(selector) .attr ("property", "value") / / set multiple properties and values: $(selector) .attr ({attribute: value,...})

Example 1: returns an attribute value

$(document) .ready (function () {$("button") .click (function () {alert ("picture width:" + $("img"). Attr ("width"));})

Pulpit Rock

Returns the width of the picture

Example 2: set the width property of an image

$(document) .ready (function () {$("button") .click (function () {$("img"). Attr ("width", "500");})

Pulpit Rock

Set the width property for the picture

Example 3: set multiple property and value pairs

$(document) .ready (function () {$("button") .click (function () {$("img"). Attr ({width: "img"});})

Pulpit Rock

Set width and height properties for the picture

These are all the contents of the article "what is the concept of attr in jquery". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report