Dynamically Add Elements with JQuery

by mmansion

HTML

<button id="myBtn">Add Element</button>

<section id="wrapper"></section>

CSS

div {
    font-size: 34px;
    line-height: 100px;
    text-align: center;
    color: white;
    width: 100px;
    height: 100px;
    background: black;
    float: left;
    margin: 10px;
}

JavaScript

var count = 1;

$('#myBtn').click(function(){

    var div = $('<div></div>');
    
    div.html(count);
    
    div.appendTo('#wrapper');
    
    count = count + 1;

});