Answers for "js event listener click"

46

javascript onclick event listener

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

js addeventlistener click

document.getElementById("ELEMENT_ID").addEventListener("click", function() {
  //insert here the code to be executed
});
Posted by: Guest on July-22-2021
33

event listener javascript

const element = document.querySelector(".class__name");

element.addEventListener("click", () => {
	console.log("clicked element");
});
Posted by: Guest on December-31-2019
9

javascript click event

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Posted by: Guest on April-10-2020
3

javascript event listener

element.addEventListener("click", function(){ 
   element.innerText = "something"; 
});
Posted by: Guest on February-19-2020
0

js addeventlistener click

// html 
<!DOCTYPE html>
<html>
  <head>
    <title>Test HTML</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  </head>
  <body>
    <form method="post">
      <div>
        <label for="terms_and_conditions">I agree to the Terms and Conditions:</label>
        <input type="checkbox" id="terms_and_conditions" value="1" />
      </div>
      <div>
        <button type="submit" id="submit_button" disabled>Sign Up</button>
      </div>
    </form>
    <script src="test.js"></script>
  </body>
</html>


// jQuery option - test.js
$("#terms_and_conditions").click(function () {
 //If the checkbox is checked.
if ($(this).is(":checked")) {
//Enable the submit button.
$("#submit_button").attr("disabled", false);
} else {
//If it is not checked, disable the button.
$("#submit_button").attr("disabled", true);
}
 });

//js options - test.js
let privacyCheck = document.querySelector("#terms_and_conditions");

privacyCheck.addEventListener("click", function () {
  if (privacyCheck.checked) {
    document.querySelector("#submit_button").disabled = false;
  } else {
    document.querySelector("#submit_button").disabled = true;
  }
});

// if you decide to use the js version remove jQuery from the header to avoid confusion
Posted by: Guest on August-18-2021

Code answers related to "js event listener click"

Browse Popular Code Answers by Language