0

Finding closet div (in next column of a table) using jquery

     <td><input type="text" name="username" id="username" minlen=5 tabindex=0/></td>
     <td><div></div></td>

And i tryed

    $("#username").next("div").html("hai");

Which is not working

8055
  • 48
  • 1
  • 7

4 Answers4

1

You should write:

$("#username").closest("td").next().find("div").html("hai");
Sang Suantak
  • 5,213
  • 1
  • 27
  • 46
1
 $("#username")
.parent()//td
.next()// next td
.find('div')//got the div, if you want the first use div:first
.html("hai");

Fiddle

0

Use $("#username").nextAll('div').first().html('hai')

http://jsfiddle.net/gmDRM/91/

Novak
  • 2,760
  • 9
  • 42
  • 63
0

I don't know why you need to add div in td. If you just want to populate next column of the same row use:

$(this).closest('tr').find('td:eq(1)').html("hai");

if you need to put "hai" in then just update the html as in

$(this).closest('tr').find('td:eq(1)').html("<div>hai</div>");
saihgala
  • 5,724
  • 3
  • 34
  • 31