I have a div class in my html file named 'btn'. In my Javascript file I use jquery to detect clicks on that btn. When the jquery function to detect clicks is written in the global scope,the function doesn't work,but when I put it inside another function and call it using developer tool console,it works. Can somebody help me out with this please?
Code for reference-
$(".btn").click(function() {
console.log('Clicked');
}
This below code works-
function clickDetection(){
$(".btn").click(function() {
console.log('Clicked');
}
}
Aucun commentaire:
Enregistrer un commentaire