How can you determine if a css class exists with Javascript?

前端 未结 10 1018
闹比i
闹比i 2020-11-27 04:14

Is there a way to determine whether or not a css class exists using JavaScript?

10条回答
  •  失恋的感觉
    2020-11-27 04:40

    Building on Helen's answer, I came up with this:

    //**************************************************************************
    //** hasStyleRule
    //**************************************************************************
    /** Returns true if there is a style rule defined for a given selector.
     *  @param selector CSS selector (e.g. ".deleteIcon", "h2", "#mid")
     */
      var hasStyleRule = function(selector) {
    
          var hasRule = function(selector, rules){
              if (!rules) return false;
              for (var i=0; i

提交回复
热议问题