How to asynchronously load CSS using jQuery?

后端 未结 8 1187
难免孤独
难免孤独 2020-12-07 23:22

I want to use jQuery to asynchronously load CSS for a document.

I found this sample, but this doesn\'t seem to work in IE:



        
8条回答
  •  甜味超标
    2020-12-07 23:54

    As per Dynamically loading css stylesheet doesn't work on IE:

    You need to set the href attr last and only after the link elem is appended to the head.

    $("")
      .appendTo('head')
      .attr({type : 'text/css', rel : 'stylesheet'})
      .attr('href', '/css/your_css_file.css');
    

提交回复
热议问题