2017-04-13 5 views
0

jQueryの - 私は1</p> <p>例で私のページ上のすべての見出しを減少したい減少見出しサイズ

<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

実際に私はカスタムクラスのようなことをしたいと思いましたが、属性を使うとはるかに簡単です:let 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

関連する問題