Javascript console.clear() Method

Introduction

Clear all messages in the console:

Press F12 on your keyboard to view the message in the console view.

Click the button to clear the console:

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript console.clear() Method</h1>

<button onclick="myFunction()">Clear Console</button>

<script>

console.log("Hello! Press the button to clear the console!");

function myFunction() {/*from   w w w .  j  a  v a2 s .  com*/
  console.clear();
}

</script>

</body>
</html>

The console.clear() method clears the console.

console.clear();

The console.clear() method will also write a message in the console: "Console was cleared".




PreviousNext

Related