I'm setting some similar functions for different pages on a website. Therefore, these functions are in the same file. When the JS file is loaded the $(function() { /*function1*/ });
and $(function() { /*function2*/ });
functions are executed. However, the elements I get via jQuery (eg, $('.elem').val();
) will not exist because they are on another page.
How do I make a function run only when a determining element is loaded?