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!'
}).appendTo('#mySelector');
Here it is in the Docs
Examples can be found at jQuery 1.4 Released: The 15 New Features you Must Know .
Related Contents:
- The preferred way of creating a new element with jQuery
- jQuery disable/enable submit button
- HTML5 dragleave fired when hovering a child element
- Detecting input change in jQuery?
- The data-toggle attributes in Twitter Bootstrap
- JavaScript data grid for millions of rows [closed]
- How to take screenshot of a div with JavaScript?
- How to enable Bootstrap tooltip on disabled button?
- how to disable DIV element and everything inside [duplicate]
- Rendering HTML inside textarea
- Creating a jQuery object from a big HTML-string
- How to manually trigger validation with jQuery validate?
- Change text color based on brightness of the covered background area?
- Bootstrap modal: is not a function
- Choosing Mobile Web HTML5 Framework [closed]
- How can I make an image carousel with only CSS?
- Placeholder for contenteditable div
- How can I detect whether an iframe is loaded?
- How to read line by line of a text area HTML tag
- How to properly use jsPDF library
- Get DOM content of cross-domain iframe [duplicate]
- Disable zoom on input focus in Android webpage
- Replacing css file on the fly (and apply the new style to the page)
- Check if element is a div
- Sorting options elements alphabetically using jQuery
- How do you get the cursor position in a textarea?
- How to make a simple image upload using Javascript/HTML
- How to properly unload/destroy a VIDEO element
- How to normalize HTML in JavaScript or jQuery?
- jQuery Mobile: Markup Enhancement of dynamically added content
- jQuery – Sticky header that shrinks when scrolling down
- How to scroll to an element in jQuery?
- Missing .map resource? [duplicate]
- How can I change the class of an element with jQuery>
- How to ONLY trigger parent click event when a child is clicked
- Reset select value to default
- How to get a HTML element from a string with jQuery
- Insert content into iFrame
- Prevent form submission with enter key
- Is the sort order of jQuery’s $().each() guaranteed?
- Where to change default pdf page width and font size in jspdf.debug.js?
- CSS3-Animate elements if visible in viewport (Page Scroll)
- Slide a div offscreen using jQuery
- Passing parameters to a JQuery function
- Second use of input file doesn’t trigger onchange anymore
- When is sessionStorage actually cleared?
- How to handle onchange event on input type=file in jQuery?
- How to display file name for custom styled input file using jquery?
- Data graphing with html [closed]
- How to start off my jquery toggles as hidden?