Martijn
Martijn

Reputation: 1

jQuery - Slide down div

I have a table cell and what I want is that if the user clicks on the table cell a div collapses (div is in another table cell).

$(function slideDown(id) { $("getdiv"+id).fadeIn(); });

The table row (hover function):

<tr class="odd" id="div96" onhover="slideDown(96)"><td>ZZZn ZZZ</td></tr>

The table cell (needs to fade in/slide down):

<tr><td id="getdiv95" class="divinside" style="display: none;">Text</td></tr>

I'm sorry for my poor English.

Demonstration image

Upvotes: 0

Views: 627

Answers (2)

Jonathan Coe
Jonathan Coe

Reputation: 1485

You are doubling up the 'div' part.

var name = $(this).attr('id');
$("#" + name).slideDown();

The way you have it written now it would look like

$("#divdiv1")...

Instead of

$("#div1")...

Also, wrap all this in a $(document).ready(function(){}); so that it triggers the click binding after all the tr elements have loaded.

Upvotes: 1

James Montagne
James Montagne

Reputation: 78630

Slide down is a function, you must invoke it in order for it to be run:

$("#div" + name).slideDown();

Upvotes: 0

Related Questions