Search code examples
javascriptvisual-studio-2010visual-web-developer-2010

How do I call a javascript that's in a separate file?


I have a .js file with:

function date() 
{
    document.getElementById("id1").innerHTML = Date();
}

And a page with:

<p id="id1"></p>
<button type="button" onclick="date()">Click here</button>

But clicking on it doesn't do anything. What's missing?


Solution

  • just add

    <script type='text/javascript' src="path_to_js_file"></script>

    on top of your html page