Home > Web Front-end > JS Tutorial > Instructions for using parents() in jQuery_jquery

Instructions for using parents() in jQuery_jquery

WBOY
Release: 2016-05-16 18:15:10
Original
1288 people have browsed it
For example:
Copy code The code is as follows:

< body>

hello


< ;p>
tonsh





$("a").parent() will get the parent object


$("a").parents() will get the parent object as


$("a").parents().filter("div") will get, which can also be written as $("a") .parents("div").
If you want the object, you can write it like this: $("a").parents("div:eq(0)").
What should I do if the content in pops up when I click the link?

Copy code The code is as follows:

var id=$("a").parents( "div:eq(1)").children("div:eq(0)").html();
alert(id);

This kind of subscript-like usage is very It's easy to get what we want, as long as we don't mix up the order of these subscripts.
Examples of using jquery parents

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute ]<script> function showParents() { $("div").css("border-color", "white"); var len = $("span.selected") .parents("div") .css("border", "2px red solid") .length; $("b").text("Unique div parents: " + len); } $("span").click(function () { $(this).toggleClass("selected"); showParents(); }); </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template