javascript - JQuery .parent click -


the use of "this" , ".parent()" in jquery gets bit confusing when goes past simple divs or datatables. have table following structure: (i can't rename of classes or id)

<table class="table1">     <tbody>         <tr>             <div class="detail">                 <table>                      <thead></thead>                      <tbody>                          <tr>                             <td>                                 <img class="picture_open" src="../location"> </td></tr></tbody></table></div></tr></tbody></table> 

what i'm trying have click function on img able grab full rowelement.

what have now:

$(".table1 tbody tr td img.picture_open").live('click', function () {     var overalltable = jquery(this).parent("table").datatable();     console.log("overalltable: " + overalltable);     var elementrow = this.parentnode.parentnode;     console.log("elementrow: " + elementrow);      var rowdata = overalltable.fngetdata( elementrow );     console.log("rowdata: " + rowdata);     if ( this.src.match('img_name') )     {         //kills table created if row opened     }     else     {         //runs ajax call create table since row not opened     } } ); 

however code have above prints out this: overalltable: [object object] elementrow: [object htmltablerowelement] typeerror: 'null' not object (evaluating 'osettings.aodata')

in problem $(this) incorrect? (not getting img class "picture_open") or overalltable variable set incorrectly .parent()? or elementrow variable set improperly parentnode? clarify errors amazing.

thanks!

parent() in jquery parse 1 level dom, should use .parents()/.closest(). fix issue.

note: .live() turned .on() in latest jquery versions. better use .on()/.click()


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -