Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No effect on slideToggle() jQuery

I'm using this very simple jQuery code:

            $("h3").click(function(){
                $(this).next("table").slideToggle("slow");
            });

The outcome itself actually works and the table does appear/disappear on click, but there is no effect of "slide" whatsoever - i've tried without "slow" and with "slow" - same result!?

Its almost like i'm just using .toggle()...

I cant see what could be wrong apart from the size of the table, which is only max, 12 rows.

Any ideas?

like image 947
benhowdle89 Avatar asked Jan 24 '11 11:01

benhowdle89


People also ask

Why slideToggle is not working?

slideToggle wasn't working because the table is not a block element. In the following update I've made it a block element (instead of display:none), and then hidden it on page load with jQuery... Nice. Probably a better fix than mine.

What does slideToggle do in jQuery?

jQuery slideToggle() Method The slideToggle() method toggles between slideUp() and slideDown() for the selected elements. This method checks the selected elements for visibility. slideDown() is run if an element is hidden. slideUp() is run if an element is visible - This creates a toggle effect.

What does slideToggle do?

The . slideToggle() method animates the height of the matched elements. This causes lower parts of the page to slide up or down, appearing to reveal or conceal the items. If the element is initially displayed, it will be hidden; if hidden, it will be shown.


1 Answers

I don't think slideToggle works on all elements... Table could be one of them... Can you place the table inside a div and run the slideToggle on the div??

Try this...

<h3>click</h3>
<div>        
<table>
            <tr>
                <td>1</td>
            </tr>
            <tr>
                <td>2</td>
            </tr>
            <tr>
                <td>3</td>
            </tr>
        </table>
</div>

and

$("h3").click(function(){
                $(this).next("div").slideToggle("slow");
            });

Working example shown here... http://jsfiddle.net/68mcY/

like image 194
Tom Avatar answered Sep 24 '22 16:09

Tom