Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery modifies the value of a specified property

Shulou Source: shulou.com Published: 2022-06-01 11:06:17 09月29日 Update

This article mainly explains the "jquery how to modify the value of the specified attribute", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "jquery how to modify the value of the specified attribute" bar!

In jquery, you can use the attr () method to modify the value of a specified attribute, which sets the property value of the selected element, with the syntax "$(selector) .attr (" attribute name "," attribute value ")" or "$(selector). Attr ({attribute name: attribute value})".

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

In jquery, you can use the attr () method to modify the value of a specified property.

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.

The syntax for setting the property value:

$(selector) .attr (attribute,value) / / single attribute / value pair $(selector) .attr ({attribute:value, attribute:value...}) / / multiple attribute / value pairs

Example:

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

Set the width property of the image

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

Set the width and height properties of the image

Thank you for your reading, the above is the content of "jquery how to modify the value of the specified attribute", after the study of this article, I believe you have a deeper understanding of how jquery modifies the value of the specified attribute, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Attributes methods learning elements content images syntax different single parameter multiple that is differences ideas situations tutorials articles methods more versions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux MariaDB Xiaomi OPPO Reno