Nodejs HTML Element Class Check is(elementSelector)

Here you can find the source of is(elementSelector)

Method Source Code

Element.prototype.is = function(elementSelector) {
  switch (elementSelector[0]) {
    case '.':/*from  ww w  .  ja va 2s  .c o m*/
      var er = new RegExp(elementSelector.replace('.', ''))
      return this.className.match(er)
      break
    case '#':
      return this.getAttribute('id') === elementSelector.replace('#', '')
      break
    default:
      return this.tagName === elementSelector.toUpperCase()
      break
  }
}

Related

  1. hasClass(classname)
    Element.prototype.hasClass = function (classname) {
        if (this == null) throw new TypeError();
        return this.className.split(' ').indexOf(classname) === -1 ? false : true;
    
  2. hasClass(cls)
    Element.prototype.hasClass = function(cls) {
      return this.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
    };
    
  3. hasClass(selector)
    Element.prototype.hasClass=function(selector){
      if((" " + this.className + " ").replace(/[\n\t]/g, " ").indexOf(" " + selector + " ") > -1 ){
        return true;
      return false;
    };
    
  4. hasStyleClass(className)
    Element.prototype.hasStyleClass = function(className) {
        if (!className)
            return false;
        if (this.className === className)
            return true;
        var regex = new RegExp("(^|\\s)" + className.escapeForRegExp() + "($|\\s)");
        return regex.test(this.className);
    };
    
  5. classContains()
    HTMLElement.prototype.classContains = function() {
      var args = arguments;
      if (args.length < 1) {
        return false;
      for (var i = 0; i < args.length; i++) {
        var classList = this.classList;
        if (!classList.contains(args[i])) {
          return false;
    ...