jQuery Structure Help
jQuery Structure Help
Hi Guys!
New to jQuery started a few months back and had to break from it for work but back on it for a mini project of mine
Needing help with the code though.
I am looking to have all my code in one jQuery js file which is called to every page in site but for instance a set of functions are only used on one page so when browsing the other pages they error because the elements don't exist on every page.
Is there any way to encase the code so that it won't auto run if that makes sense. At present my functions are within the :
$(document).ready(function(){ }
But I only want to use them when they are required. After a little bit of guidance.
Greatly appreciated.
Thanks in advance everyone.
Extra Example - The element is auto running which isn't on all pages :
-
$("form#features select#feature1").change(function(){
updateresults();
});
Obviously its erroring when select#feature1 doesnt exist when it looks for it.
Thanks again