Problem:
The problem is that the element height
of the clicked element does not change when clicked. Thus, on each click, the same height is restored and updated.
$(this).height()
will get the height of the clicked item . $(this)
inside the event handler is the jQuery object of the element on which the event occurred.
Decision:
+=40
, 40. , $(elementSelector).height() + 40
, .
. + = - = , .
$(document).on('click', '.add-case', function() {
$('.filling').animate({
height: '+=40'
}, 600);
});
.filling {
height: 10px;
width: 50%;
background: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="filling"></div>
<button class="add-case">Click</button>
Hide result