Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery selects elements and modifies attributes

Shulou Source: shulou.com Published: 2022-06-02 09:15:42 09月10日 Update

This article will explain in detail how jquery selects elements and modifies attributes. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Jquery selected elements to modify attributes: 1, the use of "$(specified element)" statement to obtain the specified element object; 2, the use of attr () method to modify the attributes of the acquired element object, the syntax is "element object .attr (attribute,value)".

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

We can use the attr () method to modify the properties of the element, and the attr () method to set or return the attribute value of the selected element.

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

$(selector) .attr (attribute,value)

Let's take a look at how to select an element and modify its property value through an example, as follows:

$(document) .ready (function () {$("button") .click (function () {$("hang"). Attr ("height", "180");}); sets the height attribute Month January Month January of the specified element

Output result:

On "jquery how to select elements and modify attributes" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Elements attributes methods objects articles more examples syntax differences good practical content parameters available through differences tutorials articles methods versions environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi MySQL Redmi Docker