if you do something like: $("div").find("span").css('background':'red').end().css('background':'green');
spans will be red, and the divs will be green. .end() reset the chain to the first selector On Wed, Apr 22, 2009 at 2:05 PM, MorningZ <morni...@gmail.com> wrote: > > 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.