Search code examples
javascriptjqueryslidedownpreventdefaultajaxform

How to make slideDown() work in ajaxForm() on THE FIRST execution of live('click')


For this particular problem i usually use preventDefault(); but in this case it doesn't work. I would be thankful if anyone helps me with this one. Here is some of my code:

            $('.place_order').live('click',function(){
                        $('#place_order_form').ajaxForm(function(){ 
                        $('#shopping_cart').slideDown(150,function(){

                        $('#shopping_cart').load('url here');

                        $('#shopping_cart').css('display','block');
                        $('#shopping_cart').css('height','290');

                        });
                        }).submit();
            }); 

It works fine after slideUp() is executed, but on first click it just loads the data without slideDown. Any help is appreciated because I am noob Jquery developer.


Solution

  • Try it like this :

    $(document).on('click', '.place_order', function(){
        $('#place_order_form').ajaxForm(function(){ 
            $('#shopping_cart').hide().load('url here', function() {
                $(this).slideDown(150);
            });
        }).submit();
    });