2

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.

2

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot Abody97, it works now. Edit: there is no 2 'b' in 'Attribute'.
@Hassinus Haha, yeah -- very sorry :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.