0

hi I am new to Javascript and I am trying to use jQuery but it doesn't work if I'm using it on another js file, but if directly inputted into my HTML file it works.

Here is the try.js file:

$("#btn1").click(fn1);

function fn1(){
    $("#heading1").fadeToggle();
} 

and the HTML code:

<!DOCTYPE html> 

<html>
    <head>
        <title>Javascript trial ANIMATIONS </title>
        <script src="jquery.js"></script>
        <script src="try.js" type='text/javascript'></script>

    </head>
    <body>

        <h2 id="heading1">SETTING UP JQUERY</h2>
        <button id="btn1">click me</button>

    </body>


<HTML>

Also how can I see the library of jQuery while typing in another js file. I'm using vs code

2 Answers2

0

May be you can use manipulation with dom when document will been load.

function fn1(){
    $("#heading1").fadeToggle();
} 

$(function() {
    $("#btn1").click(fn1);
});
John V
  • 875
  • 6
  • 12
  • thanks. I tried to paste your code into my try.js file but it still not working. I tried to put the one on my try.js file inside my HTML file and it worked. – Jovi Valderas Aug 25 '20 at 03:48
0

Check out responses to this question. You might get an idea on how to proceed.