Creating a div element in jQuery [duplicate]

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

jQuery('<div>', {
    id: 'some-id',
    class: 'some-class some-other-class',
    title: 'now this div has a title!'

Here it is in the Docs

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

Leave a Comment