- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
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
How to scroll to element in horizontal div using jQuery?
To scroll to element in horizontal div, use the scrollleft.
Example
You can try to run the following code to learn how to scroll to element in jQuery:
<html> <head> <title>jQuery Scroll</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ document.addEventListener('DOMContentLoaded', function () { var frames = document.getElementById('frames'); frames.addEventListener('click', function (e) { if (e.target.classList.contains('item')) { e.target.parentNode.scrollLeft = e.target.offsetLeft; } }); }); }); </script> <style> .myclass { width: 300px; display: flex; position: relative; overflow-x: scroll; } .item { width: 400px; background: #FFB563; margin-right: 40px; } </style> </head> <body> <div class="myclass" id="frames"> <div class="item frames-item">demo1</div> <div class="item frames-item">demo2</div> <div class="item frames-item">demo3</div> <div class="item frames-item">demo4</div> <div class="item frames-item">demo5</div> <div class="item frames-item">demo6</div> <div class="item frames-item">demo7</div> <div class="item frames-item">demo8</div> </div> </body> </html>
- Related Articles
- How to find left position of element in horizontal scroll container using jQuery?
- How to find horizontal Scroll Position using jQuery?
- How to position horizontal scroll bar at center of DIV?
- How to wrap tables with div element using jQuery?
- How to create a div element in jQuery?
- How to get the width of a div element using jQuery?
- How to get the height of a div element using jQuery?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to create div dynamically using jQuery?
- How to duplicate a div using jQuery?
- How to print div content using jQuery?
- How to scroll to element with Selenium WebDriver using C#?
- How to load a page in div using jQuery?
- How to toggle a div visibility using jQuery?
- How to Scroll to the top of the page using JavaScript/ jQuery?

Advertisements