0

I'd like to store the this file and it's path in a variable somehow like so:

var interaction ="css/interaction1/styles.css";

As later on I need to wait until this file loads before performing an action, ie wait until dynamically loaded CSS file loads before loading the content.

$(interaction).load(function(){
            loadContent();
}); 

But I get a syntax error:

Error: Syntax error, unrecognized expression: css/interaction1/styles.css

How can I do this?

user1937021
  • 10,151
  • 22
  • 81
  • 143

1 Answers1

0

Yo can't do it like that. You can do this instead:

$('<link />', {
    href: interaction,
    type: "stylesheet"
}).appendTo('head');

The above is how you load css dynamically. The interaction is not a valid selector that jQuery knows and hence the error.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
  • hi yes I already do this, bit that's not the problem, I already append the CSS to the head but then I need to wait until it loads before loading the content – user1937021 Oct 03 '14 at 09:07
  • @user, you can't reliably do that cross-browser. Some of the answers in the duplicate mention this. – Frédéric Hamidi Oct 03 '14 at 09:10