I want a parent div to be clickable through using javascript. Here is the code:
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>
But the script doesn't work. I've replaced the script by the following one, but still doesn't work:
document.querySelector("#ID").addEventListener("click", function() {
window.location.href = "https://example.com";
});
so, where am I doing wrong?