How to scroll to element in horizontal div using jQuery?

To scroll to element in horizontal div, use the scrollleft.


You can try to run the following code to learn how to scroll to element in jQuery:

Live Demo

      <title>jQuery Scroll</title>
      <script src = ""></script>
           document.addEventListener('DOMContentLoaded', function () {
              var frames = document.getElementById('frames');
              frames.addEventListener('click', function (e) {
                 if ('item')) {
        .myclass {
            width: 300px;
            display: flex;
            position: relative;
            overflow-x: scroll;
        .item {
            width: 400px;
            background: #FFB563;
            margin-right: 40px;
   <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>