Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slideDown() not working first time

Tags:

jquery

Why does slideDown() not work the first time?

$('#lnkInfo').click(function (e) {
    e.preventDefault();
    $(this).blur();
    if ($(this).text() == 'More info') {
        $('#spnMoreInfo').slideDown(200);
        $(this).text('Less info');
    }
    else if ($(this).text() == 'Less info') {
        $('#spnMoreInfo').slideUp(200);
        $(this).text('More info');
    }
});

jsfiddle here

edit: using Firefox 22.0

like image 680
notAnonymousAnymore Avatar asked Jul 10 '13 14:07

notAnonymousAnymore


2 Answers

Change the <span id="spnMoreInfo" ...> to a div. jQuery can't figure out the height before showing it. This is why it displays instantly instead of sliding.

Modified fiddle here.

like image 86
andypaxo Avatar answered Nov 19 '22 05:11

andypaxo


The problem is that you are using a <span> element that is an inline element. Try with a <div> and it will slide.

like image 42
Mir Avatar answered Nov 19 '22 04:11

Mir