我正在尝试更改我正在插入的对象的填充.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 :(得分: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'});
});
答案 1 :(得分:0)
将第二行更改为
$('#notification-count').css('padding', '1px 4px');