Jquery – How to apply css styles to dynamically added content by jQuery


I found this question many times in stackoverflow and on google, but none of the solutions worked for me.

I have a page that loads a html page with empty sections. Then jQuery starts to fill this sections dynamically. The initially loaded html page includes all js and css files and the most of the sections are built using this css files perfectly.

But there is one section, that doesn´t get right. The initially included css file and its contents are not applied to this div tag and its contents…

The project can be found at: HERE

If you scroll down in the left column you´ll find the wordcloud. This words should be viewed in alternating font sizes and colors…

This is the code fragment adding the words:

    type: "POST",
    url: "the_tagcloud_file.php",
    data: dataString,
    cache: false,
    success: function(html)


Could anybody give me an idea or just a hint to the right direction on how to solve this problem?

Thank you in advance for your help!

Best regards,


Best Solution

  • There is no function as such to add this for dynamic . Only way is to , add the css rules dynamically into the body/create a new stylsheet .


$("<style>").text("#newId { width:20px; height:30px; }").appendTo("head");