I liked this traversal examples idea, so I put some basic ones I've used in the jQuery cookbook to get it started. Could probably use some more 'interesting' examples :D.

Blair

On 9/24/06, Glen Lipka <[EMAIL PROTECTED]> 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/



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to