Answers for "div.onclick javascript"

77

javascript onclick

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});
Posted by: Guest on July-10-2020
1

onclick THIS element

<!DOCTYPE html>
//Note, this only works with a local script, it does not work if the HTML file
  //is linked to an external js file
  <html>
<body>

<h1>HTML DOM Events</h1>
<h2>The onclick Event</h2>
<h3 onclick="myFunction(this, 'red')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'green')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'blue')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'purple')">Click me to change my text color.</h3>
<script>
function myFunction(element, color) {
  element.style.color = color;
}
</script>

</body>
</html>
Posted by: Guest on April-03-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language