更改样式属性

问题描述:

我试图改变一个对象,我以.html插入的填充:更改样式属性

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

我猜不会因为它的工作看到元素#notification-count不存在。如果可能的话,完成这个的最好方法是什么?有没有存储所有.html嵌入的“主数组”?

改变第二行

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

可以使用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'}); 
});