JavaScript

[JavaScript] parent, parents의 차이

hans-j 2023. 1. 13. 17:14
parent() Method parents() Method
It only traverses one level up 
in the DOM of the selected element.
It traverses all levels up in the DOM of the 
selected element until the root i.e HTML tag.
It returns only an element that is 
the direct parent.
It returns all elements that are ancestors to the 
selected element

 

간단히 정리하면

 

parent 메소드는 한 단계의 상위 요소를 반환하고  (부모요소)

 

parents 메소드는 모~든 상위 요소를 반환한다. (모든 조상요소)

 

 

 

 

https://www.geeksforgeeks.org/what-is-the-difference-between-parent-and-parents-methods-in-jquery/

 

What is the difference between parent() and parents() methods in jQuery ? - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org