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 8243797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:38:11+00:00 2026-06-07T21:38:11+00:00

I have an html file which is structured pretty much this way: <div id=text-container>

  • 0

I have an html file which is structured pretty much this way:

<div id="text-container">
   <h1>Title 1</h1>
   <div class="text"></div>
   <div class="text"></div>
   <div class="text"></div>
   <div class="text"></div>
   <h1>Title 2</h1>
   <div class="text"></div>
   <div class="text"></div>
   <div class="text"></div>
   <h1>Title 3</h1>
   ...
 </div>

The files are built dynamically, so number of titles and text-class divs can vary.
What I am trying to achieve is to insert a elements in order to be able to jump from one title to the next, so I’m sort of after a prev() or next() but without the elements having to be siblings.

Can anyone please point me in the right direction ?

Thanks in advance for your help

  • 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-07T21:38:13+00:00Added an answer on June 7, 2026 at 9:38 pm

    Here it is: using some ternary operators: (just add a class btn to your .prev and .next buttons)

    DEMO

    $('h1').each(function(){
       $(this).data('myTopPosition', $(this).position().top );
    });
    
    var howMany = $('h1').length;
    var curr = 0; // zero based so the first 'H1' is actually '0'
    
    function correct(){
        var corr = curr === -1 ? curr=howMany-1 : curr = curr%howMany;
    }
    
    $('.btn').click(function(){
      var whatBtn= $(this).hasClass('next') ? curr++ : curr-- ;
        correct();
        var goToPos = $('h1').eq(curr).data('myTopPosition');
        $('html, body').stop().animate({ scrollTop: goToPos },1500);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have html-file. I have to replace all text between this: [%anytext%]. As I
I currently have a huge HTML file which doesn't have line breaks and just
can anyone help? I have a simple html file which i am filling via
I have a HTML file upload field from which I'm reading the file name
Let's say I'm including a file which contains html. The html have characters as
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have a file which is combination of PHP and HTML. How can i
I have written xml file which contains html tags as element like <component> <input
I have the following code which loads and html file into a webview -
I have a html form for uploading a file, which is as follows: $uploadhtml

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.