javascript consoleにあるログを全てクリアする
- 2020.09.14
- javascript
- javascript

javascriptでconsole.clearを使用して、consoleにあるログを全てクリアするサンプルコードとなります。
環境
- OS windows10 pro 64bit
- Apache 2.4.43
※windows10にApacheのインストールはこちら
console.clear使い方
console.countを利用するとconsoleにあったログを全て削除することが可能です。
1 |
console.clear() |
実行すると、以下のように表示されます。

サンプルコード
以下は、「 実行 」ボタンをクリックするごとに、変数の利用回数をカウントしていき、「 クリア」ボタンでconsoleログを削除するサンプルコードとなります。
※cssには「Bootstrap Material Design」を使用してます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>mebeeサンプル</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons"> <link rel="stylesheet" href="https://unpkg.com/bootstrap-material-design@4.1.1/dist/css/bootstrap-material-design.min.css" integrity="sha384-wXznGJNEXNG1NFsbm0ugrLFMQPWswR3lds2VeinahP8N0zJw9VWSopbjv2x7WCvX" crossorigin="anonymous"> </head> <style> .main { margin: 0 auto; margin-top: 300px; display: flex; flex-direction: column; align-items: center; font-size: 20px; } </style> <script> function hoge() { var num = 1; console.count(num); } function foo() { console.clear() } </script> <body> <div class="main"> <button type="button" class="btn btn-raised btn-primary" onclick="hoge()">実行</button> <button type="button" class="btn btn-raised btn-secondary" onclick="foo()">クリア</button> </div> </body> </html> |
ログが削除されることが確認できます。

-
前の記事
javascript 入力ダイヤログを表示する 2020.09.13
-
次の記事
javascript 1階層下の最初のhtmlタグ(子要素)を取得する 2020.09.14
コメントを書く