LoginSignup
43
40

More than 5 years have passed since last update.

HTMLで、コメントが含まれるかたまりを簡単にコメントアウトする方法

Posted at

あるかたまりをいったんコメントアウトしておきたい場合に、かたまりの中にすでにコメントが含まれていると、うまくコメントアウトできず面倒です。

例えば以下のHTMLのhoge全体をコメントアウトしたい場合、

hoge.html
<body>
  <div class="hoge">
    hogehoge
    <!-- comment comment -->
    hogehoge
  </div>
</body>

普通にやると以下のようになってしまい、うまくコメントアウトできません。

hoge-comment-NG.html
<body>
  <!-- 
  <div class="hoge">
    hogehoge
    <!-- comment comment -->
    hogehoge
  </div>
   -->
</body>

そんな時は、styleタグのコメントアウトを利用した

hoge-comment-OK-style.html
<body>
  <style>/*
  <div class="hoge">
    hogehoge
    <!-- comment comment -->
    hogehoge
  </div>
  */</style>
</body>

もしくは、scriptタグを使った

hoge-comment-OK-script.html
<body>
  <script>/*
  <div class="hoge">
    hogehoge
    <!-- comment comment -->
    hogehoge
  </div>
  */</script>
</body>

で、比較的簡単にコメントアウトができます。

参考:
http://stackoverflow.com/questions/12998915/commenting-a-commented-markup-nested-comments

43
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
40