Reputation:
I wrote a function in Html and it works well. But My teacher said we need separate the code out of HTML file. So I need to implement this code in a .js file. Can anyone tell me how to do that? I think to create a function in JS like this but it not working.
Thanks for any help!
<script>
$(document).ready(function() {
$("#down").on('click',function(event) {
$('html,div-b').animate({scrollTop: document.body.scrollHeight
-1100},"slow");
});
});
Upvotes: 2
Views: 3678
Reputation: 1597
You have use html file like this
<html>
<body>
<script src="demo.js">
</script>
</body>
</html>
and keep the js file like this demo.js file
function test(){
<!---your code here-->
}
Upvotes: 2
Reputation: 159
Write the code as it is in file and save it with .js extension and link it in html under head tag as follows
<script src="myscripts.js"></script>
Upvotes: 1
Reputation: 380
Put all the js code in a .js file, then put the code below in the html page which will call it, inside the head or the body.
<script src="myScript.js"></script>
Upvotes: 1
Reputation: 482
copy the code inside the <'script> tag and paste in a separate .js file . This is how it works
Upvotes: 2