jQuery prepend class add class to first position

var prependClass = function (sel, strClass) {
  var $el = jQuery(sel);
  if ($el.hasClass(strClass)) {
    return;
  }
  /* prepend class */
  var classes = $el.attr('class');
  classes = strClass + ' ' + classes;
  $el.attr('class', classes);
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注