Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery modifies parent node properties

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

This article mainly explains "jquery how to modify parent node properties", 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 parent node properties" bar!

Modify the parent node attributes of the method: 1, use parent () to get the specified element's parent node object, syntax "$(specified element). Parent ()"; 2, use attr () to modify the specified attributes of the parent node object, syntax "parent node object .attr ({" attribute name ":" value "," attribute name ":" value ",...})".

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

The method of modifying parent Node attribute by jquery

It needs to be divided into two steps:

Gets the parent node object of the specified element

Modify the attributes of the selected element

The following is a specific introduction.

1. Use the parent () method to get the parent node object

The parent () method returns the direct parent of the selected element.

$(specified element) .parent (filter)

2. Use the attr () method to modify the specified properties of the parent node object.

The attr () method sets the properties and values of the selected element.

Parent node object .attr ({"attribute name": "attribute value", "attribute name": "attribute value",.})

Example: modify the id attribute of the parent node

.siblings, .siblings * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } # border {border: 2px solid pink } $(document) .ready (function () {$("h3") .css ("border") "2px solid red") $("button") .click (function () {$("h3"). Parent (). Attr ({"id": "border"})) }); div (parent)

P (sibling element)

Span (sibling) h3 (this element) h4 (sibling)

P (sibling element)

Modify the id attribute of the parent node

Thank you for reading, the above is the content of "how jquery modifies parent node attributes". After the study of this article, I believe you have a deeper understanding of how jquery modifies parent node attributes, 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 nodes elements objects methods brothers learning content grammar that is ideas situations tutorials articles more versions environment computers knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft vpn macOS OPPO Reno