• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find parent table from td in Jquery

 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have following dom. and I have to select the table using class row1 for td.

if i write var row1 = $("td.row1").parent();alert($(row1).attr("class")); it prints zakas but if give

var row1 = $("td.row1").parent();
row1=$(row1[0]).parent(); then alert gives me undefine.

any help?



<table cellpadding="0" cellspacing="0" class="zakas1" border="0" width="100%">
<tr class="zakas">
<td class="row1">
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running your code, I get the <tbody> element, rather than undefined, but...

What you really want is:
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much Bear, I understand what this means, but unable to get why parent.parent does not work? is there any limit for using parent.parent.parent... ?

well I am just at chapter 2 of your book, so not fully armed, i guess i will be in better position after few weeks.

can you also help me with following code ( i know spoon feeding is not good, but its really late here and im scratching my head for long ), from following code i have to get all <a tags and assign some id and class to them so that they look like <a href="" id="sort_col1" class="sorted_by_descending">some text </a>.


[ April 28, 2008: Message edited by: Praful Thakare ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic