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 does jquery query the first child node

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to query the first child node in jquery". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to query the first child node by jquery.

Jquery query the first child node: 1, through "$(" # test "). Children ();" to get all the child nodes; 2, through "$.children (': first')" to get the first child node.

This article operating environment: Windows7 system, jquery3.2.1 version, DELL G3 computer

How does jquery query the first child node?

Jquery gets the first child node, js jquery gets the element (parent node, child node, sibling node)

First, js gets the element (parent node, child node, sibling node)

Var test = document.getElementById ("test"); var parent = Testt [XSS _ clean]; / / parent node var chils = test.childNodes; / / all child nodes var first = test.firstChild; / / first child node var last = test.lastChile; / / last child node var previous = test.previousSbiling; / / previous sibling node var next = test.nextSbiling; / / next sibling node

Second, jquery acquires elements (parent node, child node, sibling node)

$("# test1"). Parent (); / / parent $("# test1"). Parents (); / / all parent $("# test1"). Parents (".mui-content"); $("# test"). Children (); / / all child nodes $("# test"). Children ("# test1"); $("# test"). Contents () / / returns all the contents of # test, including nodes and text $("# test"). Contents ("# test1"); $("# test1"). Prev (); / / previous sibling node $("# test1"). PrevAll (); / / all previous sibling nodes $("# test1"). Next (); / / next sibling $("# test1"). NextAll () / / all sibling nodes $("# test1"). Siblings (); / / all sibling nodes $("# test1"). Siblings ("# test2"); $("# test") .find ("# test1")

Third, element screening

/ / the following methods all return a new jQuery object, which contains the filtered element $("ul li"). Eq (1); / / selects the matching element in ul li with index order 1 (that is, the second li element) $("ul li"). First (); / / selects the first matching element $("ul li"). Last () in ul li. / / Select the last matching element $("ul li"). Slice (1,4) in ul li; / / select the second to fourth element $("ul li"). Filter (": even"); / / select all the odd elements in ul li to come here. I believe you have a deeper understanding of "how to query the first child node in jquery". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 277

*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