$div_Append

by mtambulut

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

JavaScript

/*
The first option gives you more flexibilty:

***
    var $div = $("<div>", {id: "foo", "class": "a"});
    $div.click(function(){  ...  });
    $("#box").append($div);
***

And of course .html('*') overrides the content while .append('*') doesn't, but I guess, this wasn't your question.

Another good practice is prefixing your jQuery variables with $:
Is there any specific reason behind using $ with variable in jQuery

Placing quotes around the "class" property name will make it more compatible with less flexible browsers.
*/