$("body").append(function(){return $("<div/>").html("I'm a freshly created div. I also contain some Ps!").attr("id","myDivId").addClass("myDivClass").css("border", "solid").append($("<p/>").html("I think, therefore I am.")).append($("<p/>").html("The die is cast."))});
//Some style, for better demonstration if you want to try it out. Don't use this approach for actual design and layout!$("body").append($("<style/>").html("p{background-color:blue;}div{background-color:yellow;}div>p{color:white;}"));
var element = $('<div/>');var innerHTML = element.html(); // if you want set new HTML use it like this element.html('<b>new HTML</b>');var outerHTML = element[0].outerHTML;
$("<div/>", {
// PROPERTIES HERE
text: "Click me",id: "example","class": "myDiv", // ('class' is still better in quotes)css: {color: "red",fontSize: "3em",cursor: "pointer"},on: {mouseenter: function() {console.log("PLEASE... "+ $(this).text());},click: function() {console.log("Hy! My ID is: "+ this.id);}},append: "<i>!!</i>",appendTo: "body" // Finally, append to any selector
}); // << no need to do anything here as we defined the properties internally.