0

I want to add the following jquery in external javascript file.

$("a[href='#c4']").click(function() {
    $("html, body").animate({ scrollTop: 0 }, 2500);
        return false;
    });
});

How to execute this in html file?.Help me...

1
  • my external js file has some functions like:function fun_1(){.....} function fun_2(){.....} function fun_3(){.....} etc... Commented Jul 28, 2015 at 5:44

2 Answers 2

1

First include jquery file in your html and then just include your external file after your jquery file in your html page like this:

<head>
    <script src="your_jquery_file.js"></script>
    <script src="yourexternalfile.js"></script>
</head>
Sign up to request clarification or add additional context in comments.

1 Comment

@Mohamed Arifkhan A . what you did in your external javascript file is correct, you do not need to include jquery in that same file, all you need to do is to include the jquery file in your html before your external file exactly the way i did in my answer
1
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<h1>Hello World</h1>
<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript" src="path/to/your/jsFile.js"></script>
</body>
</html>

1 Comment

Dear abhijith, i did the above.but it's failure.i am strucking in adding the jquery in external js file.can i add the following jquery in same format or i have to add anything else?..... $("a[href='#c4']").click(function() { $("html, body").animate({ scrollTop: 0 }, 2500); return false; }); Thanks a lot...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.