[英]Replace H3 tag with H2 if content is uppercase using jquery
我有從PDF文件中提取的html內容。 我需要將所有H3標簽(僅包含大寫內容)轉換為H2標簽。 具有大寫/小寫內容的H3標簽將保持不變。
我正在使用它將H3標簽轉換為H2,但不確定如何僅將其應用於具有大寫內容的標簽。
$('h3').contents().unwrap().wrap('<h2/>');
任何幫助,將不勝感激。
您可以使用.filter
方法:
$('h3').filter(function() {
// check if all letters are in uppercase
return this.textContent === this.textContent.toUpperCase();
}).replaceWith(function() {
return $("<h2></h2>").append(this.childNodes);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.