Create an in-memory DIV
$("");
Add click handlers, styles etc - and finally insert into DOM into a target element selector:
$("", {
// 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: "!!",
appendTo: "body" // Finally, append to any selector
}); // << no need to do anything here as we defined the properties internally.
Similar to ian's answer, but I found no example that properly addresses the use of methods within the properties object declaration so there you go.