Ok so I’am using the Nivo Slider in my new WordPress theme.
I like loading scripts only where needed so I have it loading only for the frontpage and in my 1 file myjquery.js I make the call
$('#my_element').nivoSlider();
All’s good.
Now when I am on a different page (other than the frontpage) and since the nivoslider plugin does not load on other pages I get a javascript error. “nivoslider is not a function”. Of course, because the plugin is not loaded but the call is there.
Here’s my question. How do I prevent that error?
I tried (and perhaps I am completly wrong in doing this)
if ($("#my_element").length != 0) {
$('#my_element').nivoSlider({ pauseTime:5000});
}
thinking that checking if my_element exists and then calling the script would help but I still get the error.
What do you think it’s better to do? Take the call itself in a separate file and load that when the plugin loads? That would solve the javascript error but isn’t it a little too much to load an entire new document for just 1 or 2 lines of code?
If anyone would kindly offer a suggestion or solution I would greatly appreciate it 
