adding div into div

whee

by cliftonyeo

HTML

<button id="myBtn">add element</button>

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

CSS

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

JavaScript

var count = 1;

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

    var div = $('<div id="base"></div>');   
    
    //when such a html var div = $('<div></div>'); is written inside a jQuery function, it creates a new div!
        
    
    div.html(count);        
    
    //inside each div that jQuery creates in the above line, div.html allows the user to edit the html of those divs
    
    
    div.appendTo('#base');        
    //whatever's created is appended to the #wrapper div

    count = count + 1;
    //defines count whatever math operations you want
    

});