1document.getElementById("myBtn").addEventListener("click", function() {
2 alert("Hello World!");
3});
1var element = document.getElementById("elem");
2element.onclick = function(event) {
3 console.log(event);
4}
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>Title of the document</title>
5 </head>
6 <body>
7 <p>There is a hidden message for you. Click to see it.</p>
8 <button onclick="myFunction()">Click me!</button>
9 <p id="demo"></p>
10 <script>
11 function myFunction() {
12 document.getElementById("demo").innerHTML = "Hello Dear Visitor!</br> We are happy that you've chosen our website to learn programming languages. We're sure you'll become one of the best programmers in your country. Good luck to you!";
13 }
14 </script>
15 </body>
16</html>
1<a href='http://www.google.com' onclick='return check()'>check</a>
2
3<script type='text/javascript'>
4function check() {
5 return false;
6}
7</script>
1// Create variable for what you are trying to click
2let button = document.querySelector("#IDofItem");
3
4// Click the button
5
6if (button) {
7 button.click();
8}
9else {
10 console.log("Error");
11}
1<button onclick="myFunction()">Click me</button>
2
3<p id="demo"></p>
4
5<script>
6function myFunction() {
7 document.getElementById("demo").innerHTML = "Hello World";
8}
9</script>