Solution 1 :

maybe you can check your js and html folder location.
can try to put your js and html in a same folder, and update your script src to “./test.js”

Solution 2 :

You must use the script tag and pass the address of your “test.js” file to the src attribute. Assuming your test.js is in the same directory as your test.html file, you can use this to link them up.

<script src = "./test.js"></script>

Place the script tag just before the closing of body tag, this helps in loading the body content first and then the JavaScript, making the user experience better.

Solution 3 :

looks like the issue is how you include the script file.


If the folder “learn” is in the same folder as the HTML file, try removing the “/”


Problem :


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">

    <title>This is test Page for Learn JS</title>
    <script type="text/javascript" src="/learn/test.js"></script>
    <input type="button" value="Time" onclick="daytime()">
    <p id="now"></p>

This is test.js

function daytime() {

why click button,is nothing to do.
but insert js code to html,it’s working


Comment posted by Durgesh Kumar

kindly elaborate your question and do research before asking. A lot of questions has been answered here do some research. also go for a short tutorial for js before asking question.

Comment posted by StackSlave


Comment posted by StackSlave

Might as well just leave off the