js add click listener
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
js add click listener
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
javascript addeventlistener
var element = document.getElementById("#id");
element.addEventListener('click', function(){
console.log("click");
});
js add event listener
function eventHandler(event) {
if (event.type == 'fullscreenchange') {
/* gestire un interruttore a schermo intero */
} else /* fullscreenerror */ {
/* gestire un errore di commutazione a schermo intero */
}
}
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us