Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

javascript - 在jQuery中创建div元素[重复](Creating a div element in jQuery [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

How do I create a div element in jQuery ?

(如何在jQuery中创建div元素?)

  ask by useranon translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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个新功能 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...