Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:01:28+00:00 2026-06-09T18:01:28+00:00

I have a main div with scroll and outer-dives and inner-dives. I would like

  • 0

I have a main div with scroll and outer-dives and inner-dives. I would like when I click a button the main div scrolls to the beginning of the next inner-div the situation is better explained in this jsfidlle

http://jsfiddle.net/alamin84/63FY7/2/

The first click scroll to div 11 then 12 then 13 then to 21 which is in the next sub-div and so on

I tried to make use of the second comment of this question

Get the first and last visible element in a scrollable div by Rob W
but the variable $first which should hold reference to first visible element gives me undefined when console.logged.
The question is what is it am doing wrong? How to do this right?

Thanks in advance

****Edit****

After applying devundef’s suggestion I still can’t get the right sequence of scrolling

which is now 12 -22 -32

And should be 11 – 12 -13 -21-22…etc

In another word how to get the first visible inner div (class=”sub2”) which I can then use to get/scrollto the next visible inner div

The new fiddle

http://jsfiddle.net/alamin84/63FY7/15/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:01:30+00:00Added an answer on June 9, 2026 at 6:01 pm

    how to get the first visible inner div (class=”sub2”)?
    I did not need to have an outer selector for the outer div and inner selector for the inner div
    Only one selector for the inner div would do

    Code:

                     $("#btnScroll").click(function (event) {
    
                         var $firstinner, $lastinner, $containerinner = $("#dvmn"),
                             positions = $containerinner.offset(),
                             positionsinner = $containerinner.offset();
    
    
                         $('.sub2').each(function (i, obj) {
                             var $thisinner = $(this),
                                 positioninner = $thisinner.offset();
    
    
                             if (!$firstinner && positioninner.top >= positions.top) {
    
                                 $firstinner = $thisinner.next();
                                 if ($firstinner.length == 0) {
                    //When last inner div get to next outer div
                                     $firstinner = $thisinner.parent().next();
    
                                 }
    
                                 console.log($firstinner);
                             }
    
                         });
    
                         $containerinner.scrollTo($($firstinner), {
                             duration: 500
                         });
    
                     });
    

    Fiddle:
    http://jsfiddle.net/alamin84/63FY7/24/

    And of course using jquery.scrollTo plugin thanks to devundef

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div that scrolls (the main page does not have scrollbars) and
I have a main div on two pages ie page1.php and form.php page1.php <div
In the below shown html i have this main div as cxfeeditem feeditem and
I am working on a website where I have a main div . I
I am working on a web application (asp.net mvc3) I have a Main div.
I have a main-section div that is set to inherit it's height from its'
I have a main wrapper div that is set 100% width. Inside that i
I have a main parent div that is .resizable(). One of it's child divs,
I have a div behind the main div. Sometimes it appears and sometimes it's
I have 2 internal div's within a main div JSfiddle - http://jsfiddle.net/uwdnH/ Illustration -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.