jQuery .empty()

jQuery .empty() empties target element;

js:


$(function(){

    $('.target').click(function() { // click to empty element

        $('.elements span:not(:empty):first').empty(); // empties first not empty element

    });

});​

html:


<button class="target btn btn-primary">click me to empty element</button>



<div class="elements">

  <span>elment 1</span>

  <span>elment 2</span>

  <span>elment 3</span>

  <span>elment 4</span>

  <span>elment 5</span>

  <span>elment 6</span>

  <span>elment 7</span>

</div>

Leave a Comment