0

I'm currently building a website in which I'm using Javascript and jQuery for the first time. In my header I've got a script with a couple functions, and depending on what the user wants and the url he loads, I show some html in the body. Since part of that html needs updating I need to call one of the functions I made in my Javascript, so I currently try to do it like this:

<br />
<script type="text/javascript">
    $(document).ready(function(){
        updateMyDiv();
    });
</script>

Unfortunately, it doesn't seem to work when I call this function which I define in the script in my header from within this snippet in my body. So I wonder: how do I call the updateMyDiv() function?

kramer65
  • 50,427
  • 120
  • 308
  • 488
  • Can we see the code where `updateMyDiv` is declared? And also the error you get when this doesn't work. – Rhys Mar 23 '14 at 21:40
  • What does your browser's Console say? Does it import the first script successfully? Are you importing jQuery at the beginning of your file or at the end of your body tag? [another SO question addresses this](http://stackoverflow.com/questions/14352632/jquery-sources-position-in-html-file-is-important-or-not) – BeepBoop Mar 23 '14 at 21:40
  • 2
    This will work if a) `updateMyDiv` is global and b) defined before the ready callback is called. Without more information we can't tell you what is wrong. – Felix Kling Mar 23 '14 at 21:44
  • @FelixKling - It was b), UpdateMyDiv was also defined within the ready callback. Learned another thing, thanks! – kramer65 Mar 23 '14 at 22:35

0 Answers0