开发者

Use jQuery to disable externally linked .js/.css in header?

开发者 https://www.devze.com 2023-03-16 01:27 出处:网络
Is it possible to use jQuery to disable/comment out a header file and then later re-enable it, sort of toggle it on/off disab开发者_如何学Pythonle/enable it?Try this (for css files):

Is it possible to use jQuery to disable/comment out a header file and then later re-enable it, sort of toggle it on/off disab开发者_如何学Pythonle/enable it?


Try this (for css files):

$('link[type="text/css"]').each(function(){
  var $ele = $(this);

  //check if atribute data is set and has info
  if ($ele.attr('data') !== undefined && $ele.attr('data') !== ''){ //set, so adding that info to href attribute and emptying data attribute

    $ele.attr('href', $ele.attr('data'));
    $ele.attr('data', '');

  } else{ //not set/empty, so setting/filling it and emptying href attribute

    $ele.attr('data', $ele.attr('href'));
    $ele.attr('href', '');

  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号