To add DOM elements with jQuery, we can use the jQuery appendTo
method.
For instance, if we want to add an anchor element to the body element, we write:
$("<a/>", {
id: 'link',
href: 'http://www.example.com/',
text: 'Example Page'
}).appendTo("body");
We call $
with '<a/>'
to create a new element.
The 2nd argument we passed into $
are the attributes and the values of the element.
Then we call appendTo
on the returned object with 'body'
to attach the element to body.