- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the usage of onscroll event in JavaScript?
The onscroll event occurs when scrollbar is being scrolled for an element. You can try to run the following code to learn how to implement onscroll event in JavaScript.
Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 2px solid blue;
width: 300px;
height: 100px;
overflow: scroll;
}
</style>
</head>
<body>
<div id="content">
This is demo text. This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
This is demo text.This is demo text.This is demo text.
</div>
<p id = "myScroll"> </p>
<script>
document.getElementById("content").onscroll = function() {myFunction()};
function myFunction() {
document.getElementById("myScroll").innerHTML = "Scroll successfull!.";
}
</script>
</body>
</html>Advertisements