jQuery .empty()

jQuery .empty() empties target element;

<script>
$(function(){
    $('.target').click(function() { // click to empty element
        $('.elements span:not(:empty):first').empty(); // empties first not empty element
    });
});</script>
<div class="well">
    <p>
        <span class="target btn btn-primary">click me to empty element</span>
    </p>
    <div class="elements alert alert-block">
        <span class="label label-info">elment 1</span>
        <span class="label label-info">elment 2</span>
        <span class="label label-info">elment 3</span>
        <span class="label label-info">elment 4</span>
        <span class="label label-info">elment 5</span>
        <span class="label label-info">elment 6</span>
        <span class="label label-info">elment 7</span>
    </div>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *