Simon
Simon

Reputation: 21

Add DIV with Append, but no CSS style

I have a problem with a jQuery script. I added a new DIV into a other DIV with the function append, but the CSS style doesn't pick the declared DIV class.

For example:

<style">
  .example { background-color:#00000; }
</style>

$('#test).append('<div class="example"></div>');

I loaded the stylesheet with:

<link rel="stylesheet" type="text/css" href="./css/example.css">

Upvotes: 2

Views: 9518

Answers (1)

S L
S L

Reputation: 14318

You can try the following :

$('#test').append($('<div></div>').attr('class', 'example'));

Or

$('#test').html('<div class="example"></div>');

Upvotes: 2

Related Questions