Thanks so much Ricardo and MorningZ ! I think I have a good understanding now.
On Apr 22, 7:11 pm, MorningZ <morni...@gmail.com> wrote: > "In the example provided on the page I was viewing, > $("a").filter(".clickme").click(function(){ alert("You are now > leaving the site."); }).end() > can you describe what .end() is doing?" > > .end() is doing absolutely nothing.... > > but at that point you are back to the collection of <a>'s in the chain > and could do something further > > I use it when i fill HTML of a <div> from an AJAX call... > > say i call ".get" and the HTML i am filling in has two buttons and i > want to wire them up do an event > > <div id="Results"></div> > > and i call make an ajax call and have this "success" event > > function(results) { > > } > > and the "results" object has the HTML of, and just keeping it simple: > > <button>Do Action A</button><button>Do Action B</button> > > then ".end()" could let me wire both those in one line like > > $("#Results") //You're "at" the <div> > .html(results) //Filled, still @ <div> > .find("button:first") //You are at 1st button > .click(Action_A_Event) //Wired event, still @ button > .end() //Back to <div> > .find("button:last") //You are at 2nd button > .click(Action_B_Event); //Wired event to 2nd button > > $.get("some url"); > > On Apr 22, 4:25 pm, Ricardo <ricardob...@gmail.com> wrote: > > > > > In the docs example end() is not doing anything useful, it's just > > showing where end() fits. I use it to avoid repeating selectors: > > > $('#myform') > > .find('input') > > .click(fn..).end() > > .find('textarea') > > .mouseover(fn...).end() > > .find('label') > > .css('color', 'red'); > > > Limiting the search to #myform descendants gives me faster results, > > and end() allows for a nice chaining structure. > > > - ricardo > > > On Apr 22, 5:15 pm, JKippes <jessandthec...@gmail.com> wrote: > > > > MorningZ and Ignacio, Thanks so much for the examples. Both helped me > > > understand .end() better. > > > > I have a couple additional questions to solidfy my understanding. > > > > Is this example, > > > $("div").find("span").css('background':'red').end().css > > > ('background':'green'); > > > mainly where you see .end() being used? For when you want to attach > > > different property settings to elements within the same container? > > > > In the example provided on the page I was viewing, > > > $("a").filter(".clickme").click(function(){ alert("You are now > > > leaving the site."); }).end() > > > can you describe what .end() is doing? There isn't anything in the > > > chain after that point, and I'm not sure what it would be backing up > > > to. > > > > Thanks again. > > > > On Apr 22, 1:28 pm, Ignacio Cortorreal <luis3igna...@gmail.com> wrote: > > > > > 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.- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -