Creating a div element in jQuery

useranon picture useranon · May 15, 2009 · Viewed 1.8M times · Source

How do I create a div element in jQuery?

Answer

ian picture ian · Nov 11, 2010

As of jQuery 1.4 you can pass attributes to a self-closed element like so:

jQuery('<div/>', {
    id: 'some-id',
    "class": 'some-class',
    title: 'now this div has a title!'
}).appendTo('#mySelector');

Here it is in the Docs

Examples can be found at jQuery 1.4 Released: The 15 New Features you Must Know .