2013-02-22 110 views
0

我試圖改變一個對象,我以.html插入的填充:更改樣式屬性

$('#notification-container').html($("<div id = 'notification-count'><span id = 'not-count'>"+ count +"</span></div>")); 
$('#notification-count').style.padding = 1px 4px; 

我猜不會因爲它的工作看到元素#notification-count不存在。如果可能的話,完成這個的最好方法是什麼?有沒有存儲所有.html嵌入的「主數組」?

回答

0

改變第二行

$('#notification-count').css('padding', '1px 4px'); 
1

可以使用jquery的CSS()方法

$(function() { 
var count = 25; //default value for try 
$('#notification-container').html('<div id="notification-count"><span id="not-count">'+ count +'</span></div>'); 
$('#notification-count').css({'padding':'1px 4px'}); 
});