The preferred way of creating a new element with jQuery
问题 I\'ve got 2 ways I can create a <div> using jQuery . Either: var div = $(\"<div></div>\"); $(\"#box\").append(div); Or: $(\"#box\").append(\"<div></div>\"); What are the drawbacks of using second way other than re-usability? 回答1: 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