Ahhh...thank you for correcting me. I misunderstood the method then. I was under the impression that it returned the original.
Thanks. -----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of MorningZ Sent: Wednesday, April 22, 2009 1:49 PM To: jQuery (English) Subject: [jQuery] Re: Can you help me understand .end() ? "Essentially the end method returns the result of the very first selector. " Not an accurate statement if you say var $obj = $("div").find("span").find("img"); and do $obj.end(); that would be a selection of <span> tags, *not* the first selector of just the <div> tag Right from the docs "Revert the most recent 'destructive' operation, changing the set of matched elements to its previous state (right before the destructive operation)." On Apr 22, 2:20 pm, "Andy Matthews" <li...@commadelimited.com> wrote: > Essentially the end method returns the result of the very first selector. > > Andy matthews > > -----Original Message----- > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] > On > > Behalf Of MorningZ > Sent: Wednesday, April 22, 2009 1:06 PM > To: jQuery (English) > Subject: [jQuery] Re: Can you help me understand .end() ? > > Say you have the html of > > <div> > <span>One</span> > <span>Two</span> > <span>Three</span> > </div> > > and say: > var $obj = $("div"); > > your jQuery object, $obj, will be just the <div> tag > > Now if you say > > var $obj = $("div").find("span"); > > that would first be an object representing the <div> and the ".find()" > makes it be an object of the 3 <span> tags > > If the statement was (and granted this doesn't make sense, but just an > example) > > var $obj = $("div").find("span").end(); > > that would be just the <div> tag again.... although walking through > the selector, $obj would have been the <div>, then would have > represented the "found" <span> tags, called ".end()" backs off the > ".find()" and goes back to the div > > thinking of the chained command like a deck of cards helps :-) > > On Apr 22, 12:41 pm, JKippes <jessandthec...@gmail.com> wrote: > > Please referencehttp://docs.jquery.com/How_jQuery_Works, the > > Chainability segment. > > > I'm confused on the given description of .end(): > > > You can take this even further, by adding or removing elements from > > the selection, modifying those elements and then reverting to the > > old selection, for example: > > $("a") > > .filter(".clickme") > > .click(function(){ > > alert("You are now leaving the site."); > > }) > > .end() > > > <a href="http://google.com/" class="clickme">I give a message when > > you leave</a> > > > Methods that modify the jQuery selection and can be undone with > > end(), are the following: > > > add(), > > children(), > > eq(), > > filter(), > > find(), > > next(), > > not(), > > parent(), > > parents(), > > siblings() and > > slice(). > > > What does reverting and undone mean here? When I run the code, the > > link click event runs the alert, I hit Ok, and it passes me to Google. > > So the words reverting and undone confuse me, as I would take this > > to mean the modified click event would be "undone" and never executed. > > So what does .end() really do? A friend thinks it could be a chain > > terminator, though he never uses it. Is it just a cleanup thing > > part of good practice and not technically needed? > > > Thanks for educating a real jQuery beginner.