How to add a CSS class depending on URL path?

后端 未结 3 564
渐次进展
渐次进展 2021-01-26 01:56

How can I add an CSS class to an div depending on what path I am on, including that it should not mather if I had # in it?

3条回答
  •  天命终不由人
    2021-01-26 02:21

    jQuery(function($){
       switch(window.location.hash){
          case "vs":  $(".popup").addClass("class1"); break;
          case "bod":  $(".popup").addClass("class2"); break;
          case "ptf":  $(".popup").addClass("class3"); break;
       }
    });
    

提交回复
热议问题