0
When I develop a website, I always save it inside a folder called js, and generally the file name is acoes.js. What happens is I call this file on every page. And sometimes, I create a function for a particular page, and when I’m on another, as there is no class nor the id containing this function, gives error in the console.
I always have to check whether it exists or not, that way:
if($('#MINHA_ID').length>0){ MINHA FUNÇÃO});
Me doing this check, that this id is being used or not on this page, no problem.
Is this the right way? or should I make one js separate for each page?
The ideal is to have a js file with generic functions to be used on several pages, thus reusing code. But if you need to create something specific for a page, you can create a function on the page itself.
– Alexandre Strevenski
Could provide an example?
– Alexandre Strevenski