Quiero que se pueda hacer clic en un div principal mediante el uso de javascript. Aquí está el código:
document.getElementById("box").addEventListener("click", function() { window.location.href = "https://example.com"; }); #box { width: 200px; height: 200px; background-color: red; } <div id="box"> //something </div>Pero el guión no funciona. He reemplazado el script por el siguiente, pero sigue sin funcionar:
document.querySelector("#ID").addEventListener("click", function() { window.location.href = "https://example.com"; });Entonces, ¿dónde estoy haciendo mal?