Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>from <a href="http://api.jquery.com/closest/" rel="noreferrer">http://api.jquery.com/closest/</a></p> <blockquote> <p>The <strong>.parents()</strong> and <strong>.closest()</strong> methods are similar in that they both traverse up the DOM tree. The differences between the two, though subtle, are significant:</p> <p><strong><em>.closest()</em></strong> </p> <ul> <li>Begins with the current element</li> <li>Travels up the DOM tree until it finds a match for the supplied selector</li> <li>The returned jQuery object contains zero or one element</li> </ul> <p><strong><em>.parents()</em></strong></p> <ul> <li>Begins with the parent element</li> <li>Travels up the DOM tree to the document's root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied</li> <li>The returned jQuery object contains zero, one, or multiple elements</li> </ul> <p><strong><em>.parent()</em></strong></p> <ul> <li>Given a jQuery object that represents a set of DOM elements, the .parent() method allows us to search through the parents of these elements in the DOM tree and construct a new jQuery object from the matching elements.</li> </ul> <p><strong><em>Note:</em></strong> <em>The .parents() and .parent() methods are similar, except that the latter only travels a single level up the DOM tree. Also, $("html").parent() method returns a set containing document whereas $("html").parents() returns an empty set.</em></p> </blockquote> <p>Here are related threads:</p> <ul> <li><p><a href="https://stackoverflow.com/questions/8975985/whats-the-difference-between-closest-and-parentsselector">What&#39;s the difference between .closest() and .parents(&#39;selector&#39;)?</a></p></li> <li><p><a href="https://stackoverflow.com/a/2200805/149206">https://stackoverflow.com/a/2200805/149206</a></p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload