CSS loaded dynamically via javascript but not applied

I have a javascript file that load a content via AJAX and apply the appropriate style by loading the corresponding CSS file:

var ssioCss = document.createElement("link");
ssioCss.setAttribute("href", baseURL + "ssio-plugin.css");
ssioCss.setAttribute("type", "text/css");
document.head.appendChild(ssioCss);

But unfortunately, the style is not applied, event the file was correctly loaded (checked via chrome inspector).

Did I missed something? Any idea how to fix that?

Thanks in advance.

Answers


You're missing something:

ssioCss.setAttribute("rel", "stylesheet");

Otherwise there's nothing to tell the browser what to do the with the downloaded file. Just in case you're wondering, type = "text/css" only restricts the MIME Type.


Need Your Help

Cocos2d Timer to delete objects

iphone objective-c cocos2d-iphone

Im trying to create a timer in Cocos2d in which an object is created and deleted 5 seconds after it is created. Does anyone know how to make this?

how to fit textbox in the table cell

asp.net html css

.. been trying to fit the textbox (auto adjust the textbox width) within HTML table's cell but no luck.. can anyone please help? thanks

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.