2011-08-12 50 views

回答

1

,如果你想創建一個DIV:

$('<div></div>').attr('id','my-funky-id').appendTo('parentselector'); 
// or 
$('parentSelector').append($('<div id="'+my_id+'">'));/// my_id = var holding the id 

,如果你已經有一個DIV,但要將其插入到另一個元素(移動):

$('#'+my_id).appendTo('parentSelector'); 
0
$('#' + id).appendTo('div.your-other-div'); 
0

Depe發現你的意思是「動態ID」,如果你的意思是一個隨機的ID,那麼這樣的事情應該工作:

$('<div></div>').prop('id', 'd' + Math.ceil(Math.random()*20000)).appendTo($('#idofdivtoinsertinto'));