0
jQuery syntax: var $div = $("<div>", test)
I have found the following code in a jQuery exercise: var test = { id: "div", class: "divclass", css: { "color": "Green" } }; var $div = $("<div>", test); I canât understand the syntax in the last line. Does test add properties to jQuery object of $("<div>â)? I have never seen that two things are inside the brackets divided by a comma in a jQuery object: $(âaâ, b)
1 Answer
0
Yes. Using this syntax we can add a new tag in our DOM.
And here, set the properties of the div tag using the test variable.
Ex:-
var $div = $("<div>", {id: "foo", "class": "a"});
$div.click(function(){ /* ... */ });
$("#box").append($div);
Hope you get it.