0
I have several pages, I wonder if it is possible to use the same JS on the same page.
For example:
I have a HOME page, where I carry the pages "son" inside a
div
(content), but for each page, I need to create a new file JS.
$("#lista_cli").click(function(){
$('#content').css('display', 'none');
$("#content").load('lista_clientes.php');
$("#content").fadeIn(2000);
});
$("#cadastro_cli").click(function(){
$('#content').css('display', 'none');
$("#content").load('cadastra_cliente.php');
$("#content").fadeIn(2000);
});
I’ve been doing some tests, at some point, when I give a ALERT
in the archive JS of the home page, in one content of the other page (after loaded), it displays me a alert
correctly, however the requests AJAX don’t work. Maybe I got a little confused, but basically:
It is possible to use the same JS on several pages? is recommended?
Just to complement, code reuse is a good practice, as Arnaldo has already said, not only to avoid unnecessary duplication of code, but to facilitate maintenance. Imagine that you have a generic Alert that you use on all screens and you need to change all the texts from that Alert. Instead of going page by page to tidy up each Alert code, you, having shared (reused) it on other pages, can change the code only 1x and have a "global effect".
– Raphael Vizoni