I have the following in my main html:
jQuery(document).ready(function(){
jQuery('body').flvplay(songlist, {something});});
I wanted to move this to a separate JS file and make a function call from the main html. I created the new JS with the following:
play()
{
jQuery('body').flvplay(songlist, {something});
}
Finally, I called the play function from the main html after including the new JS file:
<script type="text/javascript">
play();
</script>
This is not working for some reason. Is there anything wrong with the above? Thanks for helping.
You need to declare functions using the
functionkeyword:Additionally, you deleted
$(document).ready(...), which is important because otherwise you might be trying to manipulate elements that do not exist because they have not loaded yet. You may want to modify your calling code to look like this:If you don’t use the
functionkeyword, the code in the referenced file will be parsed like this: