Home  >  Article  >  Web Front-end  >  The difference between finding parents and closest methods in jquery_jquery

The difference between finding parents and closest methods in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 17:11:301029browse

1. Return value The former can return multiple elements or can only return 0 or 1

2. The stopping time is different. The former is all the superior elements, that is, all the way to the root, which is usually the body. The latter is until it is found, and it stops when it finds one

3. The starting elements are different. The former starts from the parent element and the latter starts from itself

The code is as follows:

Copy the codeThe code is as follows:




Find parent element






Add border to ancestors






<script><br> $("p").closest("div[id='div1']").css("border", "1px solid blue");<br> </script>

You can try changing closest to parents
Statement:
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