This question already has an answer here:
(这个问题在这里已有答案:)
(jQuery document.createElement等价?)
(13个答案)
How do I create a div element in jQuery ?
div
(如何在jQuery中创建div元素?)
As of jQuery 1.4 you can pass attributes to a self-closed element like so:
(从jQuery 1.4开始,您可以将属性传递给自闭元素,如下所示:)
jQuery('<div/>', { id: 'some-id', "class": 'some-class', title: 'now this div has a title!' }).appendTo('#mySelector');
Here it is in the Docs
(这是在Docs中)
Examples can be found at jQuery 1.4 Released: The 15 New Features you Must Know .
(例子可以在jQuery 1.4发布:你必须知道的15个新功能 。)
1.4m articles
1.4m replys
5 comments
56.8k users