jQuery-减少标题大小

jQuery-减少标题大小,jquery,Jquery,我想把我页面上的所有标题减少一个 示例: Hi->Hi Moin->Hi 在jQuery中实现这一点的最佳方法是什么 谢谢 可能不是最佳解决方案,但您可以尝试以下方法: $("h1, h2, h3, h4, h5").each(function() { if($(this).is("h1")) { $(this).replaceWith("<h2>" + $(this).text() + "</h2>"); } else if($(this).is(

我想把我页面上的所有标题减少一个

示例:

Hi->Hi
Moin->Hi

在jQuery中实现这一点的最佳方法是什么


谢谢

可能不是最佳解决方案,但您可以尝试以下方法:

$("h1, h2, h3, h4, h5").each(function() {

  if($(this).is("h1")) {
    $(this).replaceWith("<h2>" + $(this).text() + "</h2>");
  }
  else if($(this).is("h2")){
    $(this).replaceWith("<h3>" + $(this).text() + "</h3>");
  }
  else if($(this).is("h3")){
    $(this).replaceWith("<h4>" + $(this).text() + "</h4>");
  }
  else if($(this).is("h4")){
    $(this).replaceWith("<h5>" + $(this).text() + "</h5>");
  }
  else if($(this).is("h5")){
    $(this).replaceWith("<h6>" + $(this).text() + "</h6>");
  }

});
$(“h1、h2、h3、h4、h5”)。每个(函数(){
如果($(此).is(“h1”)){
$(this.replace为(“+$(this.text()+”);
}
else if($(this).is(“h2”)){
$(this.replace为(“+$(this.text()+”);
}
如果($(此).is(“h3”)){
$(this.replace为(“+$(this.text()+”);
}
如果($(此).is(“h4”)){
$(this.replace为(“+$(this.text()+”);
}
如果($(此).is(“h5”)){
$(this.replace为(“+$(this.text()+”);
}
});

您有任何尝试吗?您能添加更多您需要的信息吗?如果要增大或减小字体大小。试试这里:实际上我想对自定义类做类似的事情,但意识到使用属性更容易:让headIndex=parseInt($(this).attr(“数据头索引”))| | 0;不过,我认为最初的问题总体上可能很有趣。