Linked Questions

Popular Questions

Prepend with last added at bottom

Asked by At

I have the following code:

HTML:

   <div class="row" id="dvNumbers" style="margin-bottom:20px; margin-top:10px">
      <div class="col-md-3">
           <a class="btn btn-primary" data-val="1" id="btnNbr">Add Number</a>
      </div>
  </div>

jQuery:

    var w = 0;

    // start
    $('[id*=btnNbr]').on('click', function () {
        w++;
        var str = "";
        str += "<label>" + w + "</label><br\>";            
        $('#dvNumbers').prepend(str);          
    });

The result I am seeing is as such:

enter image description here

I like to have it so that it is as such that the last added number is at the bottom prior to the Add Number button as such:

1

2

3

4

Related Questions