Good point about using $("../",this) as an alternative to using $(this).parent(), though I've noticed that the syntax should be $("..",this) to return the parent, while $("../",this) returns siblings. Does this sound right?
Cheers, George Adamson Glen Lipka wrote: > > Parent() works, and also xPath expressions: (damn, jquery has so much > power > on traversal) > refer to: http://jquery.com/docs/Base/Expression/XPath/ > > Example: $("../",this) should get the parent too. > > It actually would really help "Getting Started" if someone would write a > bunch (like 100) of common traversal examples. There are a bunch of > examples on several different sites, but they lack explanation of what > they > are doing. (Like the URL above). A traversal cheat sheet! :) > > On thing that has REALLY helped me is to use MS Script Editor. You put > the > word debugger; in your code and then use the watch word functionality to > explore the jQuery object. So you can type in anything like $("../",this) > and see what that gives you. Easy to play around and see what hits what > node. > > Hope this helps. > > Glen > > On 9/23/06, Rey Bango <[EMAIL PROTECTED]> wrote: >> >> I'm just getting into the ins and outs of JQuery but I believe you can >> use the .parent() method to do that. Something like this: >> >> $("p").parent() >> >> HTH. >> >> Rey... >> >> Bruce McKenzie wrote: >> > What's the preferred/simplest way to get hold of the immediate parent >> of >> > a DOM element? >> > >> > I've got a table in which some cells are editable (I'm using the >> > excellent editable plugin by Dylan Verheul). When a cell is changed, >> the >> > database gets updated and the Ajax callback needs to recalculate the >> sum >> > of the cells in the row. >> > >> > So, I have this in the editable object: >> > >> > callback:function(){ >> > recalcEstimate ( myCell ) ; >> > // myCell is jQuery obj containing one TD tag >> > } >> > >> > and this is what gets called: >> > >> > function recalcEstimate(myCell){ >> > var myRow = myCell[0].parentNode; >> > // this seems weird, but I couldn't retrieve the DOM element >> > // I want from anything like "myCell.parent()" >> > var total=0; >> > $( 'td.editable', myRow ).each(function(){ >> > var aNum = $( this ).text(); >> > total += Number(aNum) ; >> > }); >> > $(myRow).find('.total').html( total.toFixed(1) ) ; >> > } >> > >> > This works -- but I don't think I've seen any code written by someone >> > who knows what they are doing (e.g., in the plugins or tutorials) that >> > looks like this :-) >> > >> > What's the "best practice"? >> > >> > Bruce >> > http://www.2MinuteExplainer.com >> > >> > _______________________________________________ >> > jQuery mailing list >> > discuss@jquery.com >> > http://jquery.com/discuss/ >> > >> >> _______________________________________________ >> jQuery mailing list >> discuss@jquery.com >> http://jquery.com/discuss/ >> > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/Help-finding-parent-element-tf2324683.html#a6476467 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/