When clicking button, increase or decrease height of a div

Asked

Viewed 1,569 times

3

I created a button inside a div (#divteste) and would like to click on that div button(#divteste) increase the height and click again on the button to decrease the height and if there is a way to carry out a transfer or Animate.

Meu código atual

1 answer

7


Try with the Animate like this

$('#seuBotao').on('click', function(){
    if($('.sua-div').height() == 30){
         $('.sua-div').animate({"height" : "200px"}, 200);
    }else{
        $('.sua-div').animate({"height" : "30px"}, 200);
    }
});

Where 200 would be the time in milliseconds for animation; You can also create by adding classes:

 $('#seuBotao').on('click', function(){
        if($('.sua-div').hasClass('pequena')){
             $('.sua-div').animate({"height" : "200px"}, 200);
             $('.sua-div').removeClass('pequena');
             $(this).attr('value', 'Diminuir');
        }else{
            $('.sua-div').animate({"height" : "30px"}, 200);
            $('.sua-div').addClass('pequena');
            $(this).attr('value', 'Aumentar');
        }
    });
  • I tried here not getting it

  • Added the jquery library to your website?

  • Ready it worked I was putting the code in the wrong place

  • You’re cheering up the way you want it?

  • could change the value from inside the boot? type increase and when increase appear decrease

  • I edited the answer, just change the button value property in each event

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.