Add Div Dynamically using JQuery

Try this:

$('.button').click(function() {
    $('#myContainer').append('<div>the new guy</div>');
});

Your example updated on jsFiddle

$("input[type=submit]").click(function(){
    $("<li />").html("item").appendTo("ul");
})

You can create elements using $("<tag />") and set attributes, add classes and so on. Then append where you want.


You can add a new element to an existing parent like so:

select the element to added the new <div>/<li> to and use .append()

$("#id").append("<div>foo</div>");

http://api.jquery.com/append/

Alternatively, you can use the .html()

http://api.jquery.com/html/

Tags:

Html

Jquery