change css link and wait till new css is loaded

前端 未结 6 537
南笙
南笙 2020-12-17 22:48

I wonder whether it\'s possible to change stylesheet link of the loaded document, then wait till the new css is loaded, and then run appropriate js code

thanks for a

6条回答
  •  余生分开走
    2020-12-17 23:02

    html:

    
    

    code:

    $("#mystylesheet").load(function(){
      //Your javascript
    }).attr("href", "/new/path/to/css.css");
    

    This will replace your current CSS, and execute any code within the .load() handler after the new CSS file has been fetched.

提交回复
热议问题