From 2767a710695cc213dd4d49d2a9dbe8ffc33695fe Mon Sep 17 00:00:00 2001 From: Ansh srivastava <75901110+ansh-srivastava@users.noreply.github.com> Date: Mon, 6 Mar 2023 19:24:01 +0530 Subject: [PATCH] Create example.js --- example.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 example.js diff --git a/example.js b/example.js new file mode 100644 index 00000000..864dbedd --- /dev/null +++ b/example.js @@ -0,0 +1,14 @@ +//Certainly! Here's a simple example of JavaScript code that will display a message in the console when a button is clicked: +// Get a reference to the button element +const button = document.querySelector('button'); + +// Add a click event listener to the button +button.addEventListener('click', () => { + // Log a message to the console + console.log('Button clicked!'); +}); + +//This code uses the querySelector method to get a reference to the button element on the page, +//and the addEventListener method to add a click event listener to the button. When the button is clicked, +//the code inside the event listener function will execute, which in this case logs a message to the console using the console. +//log method.