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

How jquery modifies parent node properties

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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