Let’s say we have the following JavaScript/jQuery code below
function createElement(i, value) {
return $('<div>', { id: "field" + i, text: value});
}
I have a div with an id of “container” and then I do:
var c=$("container");
c.append(createElement(1, "hello, world!");
Now I’ve got 2 questions
-
Does the createElement function use jQuery to return an HTML string that gets appended to container or does it dynamically create a DOM element that gets appended to the container?
-
I’m unfamiliar with this kind of jQuery where you actually create the HTML string (or DOM element) via the $() selector. I tried looking for the documentation on this subject in jQuery’s website but I couldn’t find it. Can somebody point me in the right direction?
It creates the DOM element on the fly, and appends that.
http://api.jquery.com/jQuery/#jQuery2