2017-04-13 44 views
0

我想通過一個jQuery的 - 減少標題的大小

例子來降低我的網頁上的所有標題:

<h1>Hi</h1> -> <h2>Hi</h2> <h3>Moin</h3> -> <h4>Hi</h4>

什麼是實現這一目標的jQuery的最佳方法是什麼?

謝謝!

+2

任何從你身邊的嘗試? –

+0

你可以添加更多信息你需要什麼?如果你想增加或減少字體大小。嘗試在這裏:http://stackoverflow.com/questions/24241457/increasing-decreasing-font-size-on-button-click –

+0

其實我想爲類自定義類做一些事情,但意識到使用屬性它更容易:讓headIndex = parseInt($(this).attr(「data-head-index」))|| 0; 儘管如此,我仍然認爲最初的問題可能會讓人感興趣。 – Gustav

回答

0

可能並非最好的解決辦法,但你可以試試這個:

$("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>"); 
    } 

}); 

DEMO