1document.getElementById("myBtn").addEventListener("click", function() {
2 alert("Hello World!");
3});
1document.getElementById("ELEMENT_ID").addEventListener("click", function() {
2 //insert here the code to be executed
3});
1const element = document.querySelector(".class__name");
2
3element.addEventListener("click", () => {
4 console.log("clicked element");
5});
1// html
2<!DOCTYPE html>
3<html>
4 <head>
5 <title>Test HTML</title>
6<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
7 </head>
8 <body>
9 <form method="post">
10 <div>
11 <label for="terms_and_conditions">I agree to the Terms and Conditions:</label>
12 <input type="checkbox" id="terms_and_conditions" value="1" />
13 </div>
14 <div>
15 <button type="submit" id="submit_button" disabled>Sign Up</button>
16 </div>
17 </form>
18 <script src="test.js"></script>
19 </body>
20</html>
21
22
23// jQuery option - test.js
24$("#terms_and_conditions").click(function () {
25 //If the checkbox is checked.
26if ($(this).is(":checked")) {
27//Enable the submit button.
28$("#submit_button").attr("disabled", false);
29} else {
30//If it is not checked, disable the button.
31$("#submit_button").attr("disabled", true);
32}
33 });
34
35//js options - test.js
36let privacyCheck = document.querySelector("#terms_and_conditions");
37
38privacyCheck.addEventListener("click", function () {
39 if (privacyCheck.checked) {
40 document.querySelector("#submit_button").disabled = false;
41 } else {
42 document.querySelector("#submit_button").disabled = true;
43 }
44});
45
46// if you decide to use the js version remove jQuery from the header to avoid confusion