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
[email protected]
http://jquery.com/discuss/

Reply via email to