iRector
iRector

Reputation: 1984

Change style properties of a html embedded object

I'm trying to change the padding of an object that I'm inserting with .html:

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

I'm guessing that doesn't work due to it seeing the element #notification-count as not existing. If possible, what would be the best way of accomplishing this? Is there some 'master array' with all the .html embeddings stored or something?

Upvotes: 0

Views: 188

Answers (2)

ASPMaker
ASPMaker

Reputation: 303

you can use jquery .css() method

$(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'});
});

Upvotes: 1

Tamil Selvan C
Tamil Selvan C

Reputation: 20209

Change the second line as

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

Upvotes: 0

Related Questions