I have one .js file for the whole website, in some places in the code I put $(document).on event inside if condition to make the event only available in certain pages.
example:
if( $(".some-class").length )
{
$(document).on("click",".some-button",function(){
......
});
}
The code runs fine, but I am worried if this is bad practice? or if it will cause bugs on some older browsers?
I don't think there will be any benefit to performance from what I did, but if it is not harmful then I want to keep it, because it will be difficult to run over all the code to change it.
Aucun commentaire:
Enregistrer un commentaire