Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Find Next Element Inside Table Row

I have this function:

$("span.expandimg").click(function(){
  $(this).nextAll(".toggle_container:first").slideToggle("slow");
});

That worked fine with:

<span class="expandimg"><a href="#"><img id="iexpand" src="images/expand.png" border="0" /><img id="icollapse" src="images/collapse.png" border="0" /></a></span>&nbsp;<a href="asdfa" class="DSF">First Link</a>

<div class="toggle_container">
Some Text
</div>

But now I'm putting "expandimg" inside a table column and "toggle_container" inside another column. Something like this:

<tr>
  <td><span class="expandimg">......</td>
  <td><div class="toggle_container">.....</td>
<tr>

How can I find the "toggle_container" element now? I want to click on "expandimg" to expand the "toggle_container", but it's not working with the function I have.

Thanks!

like image 281
user1005793 Avatar asked Oct 20 '11 20:10

user1005793


1 Answers

$("span.expandimg").click(function(){
    $(this)
        .closest("tr")
        .find("td .toggle_container")
        .slideToggle("slow");
});
like image 168
Shef Avatar answered Oct 31 '22 15:10

Shef