jquery parent() issue -


i speak english not well, show code , problem right now.

here code:

html:

<td class="yyyy">     <a id="delete" href="#" >anchor</a> </td>    

js:

$(function(){     $("a#delete").click(function(e){         e.preventdefault();          var s = $(this).parent("td").attr("class");         alert(s);                });     }); 

it returns alert "undefined". think must "yyyy".

can me?

thanks! http://jsfiddle.net/nguyenthanh/weayw/4/

i fixed problem write html content of table (tr,td). again!

<table> <tr>     <td class="yyyy">             <a id="delete" href="#" >anchor</a>     </td> </tr> </table>  $(function(){     $("a#delete").click(function(e){         var s = $(this).parent("td").attr("class");                      alert(s);            e.preventdefault();      }); }); 

you can't have <td> in fiddle, should enclosed within <table> , <tr>:

<table> <tr>     <td class="yyyy">       <a id="delete" href="#">anchor</a>     </td> </tr> </table> 

try one:

    $("a#delete").click(function (e) {        var s = $(this).parent("td").attr("class");        alert(s);        e.preventdefault();     }); 

find in fiddle


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -