How to create a DOM element using jQuery.
Part 1 (how in the old version)
These steps would be.
- to generate a jQuery object
- attributes, such as adding a jQuery object
- Get elements and registering a jQuery object as a child element
And in order to do the following. Furthermore, no problem as \"jQuery\" part of the \"$\". You can chain methods.
var objtest = $('<a>');//<a></a> objtest.attr('href', 'http://example.com/');//<a href="'http://example.com/"></a> objtest.text('example');//<a href="'http://example.com/">example</a> objtest.appendTo( document.body );//<body><a href="'http://example.com/">example</a></body>
Part 2 (version 1.4 or later)
Above part 1-1.2 to the dash.
$('<a>', { href: 'http://example.com/', text: 'example' } ) .appendTo( document.body );
Other, specify width and height, or set checked check box.
For more information, see website (Japan words).
http://idocsq.net/page/223
タグ:JavaScript