My aim is to add an onClick event to an element when the screen is below 700px wide and to remove the clickable area if its above 700px. Am I going about this in a good way? How would I add onClick="myFunction()" to a div in HTML?
myFunction();
window.addEventListener("resize", function(event) {
myFunction();
});
function myFunction() {
var i = document.all?document.body.clientWidth:window.innerWidth;
if(i > 701) {
// Adds onClick
}
if(i < 701) {
// Removes onClick
}
}
clickinstead ofresize