1

I am trying to move my jquery code form script tags inside html to separate javascript files but there is no code complete in the new file and the $ variable is not recognized as jQuery. The code runs fine though. In my index.js file which does not have code complete in visual studio:

$( function(){
        $("a").attr({href:"http://reddit.com"}).text("reddit.com")
        $(".header").css("color","red");
    }
);    

In my html file I loaded jquery before index.js which has the jquery code inside it:

<html>
<head>
    <link rel="stylesheet" href="/static/css/style.css">
    <script type="text/javascript" src="/static/js/jquery.js"></script>

    <script type="text/javascript" src="/static/js/index.js"></script>

    <title>Welcome</title>

    <h1 class="header">Welcome to the test site</h1>
    <a href = "http://www.google.com">Google.com</a>
</head>
<body>
    <input type="button" onclick="location.href='/login';" value="Login" />
</body>
</html>

Does anyone know why my index.js does not recognize the jQuery library and assign $ to jquery variable? Thanks and let me know if I need to clarify anything.

1
  • Open Developer Tools Console. Do you see any errors? Commented Feb 19, 2017 at 22:33

1 Answer 1

1

Okay so all I needed to do was install with npm:

npm install --save @types/jquery
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.