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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:22:35+00:00 2026-06-11T16:22:35+00:00

I’m writing a site and using jQuery. I’ve got an issue where I want

  • 0

I’m writing a site and using jQuery. I’ve got an issue where I want to do two distinct changes to the DOM. Basically, I’m calling $.toggle() on a couple of divs, one of which is hidden, and the other is visible.

<div>
    <button onclick='javascript:$(".panel").toggle()'>Toggle!</button>
    <div class="panel">Content1</div>
    <div class="panel hide">Content2</div>
</div>

The problem I have is that the browser is re-rendering the page after each call to toggle(). This switch is invisible to the naked eye, but results in some strange behaviour.

What ends up happening is that the first .panel div is found, and that is toggled to be hidden. The second .panel div is then toggled, and is shown. In between these calls, the browser detects a DOM change and re-renders the page with both divs hidden.

If these divs are at the bottom of a page, the page becomes shorter for a fraction of a time, so the page scroll position jumps up before the second div becomes visible.

Flipping the visibility back the other way doesn’t have the same effect, because now the browser briefly renders the page with both divs visible, before hiding the second div. There’s no scroll issues then.

Is it possible to somehow place some sort of hold or lock over these two actions to instruct the browser not to reflow, scroll, or otherwise render the page until the hold/lock has been released? In that case, the browser would render the page with a single .panel, the javascript would run and the browser would then be instructed to re-render the changed DOM.

Edit

I’ve added a JSFiddle of what I mean over at http://jsfiddle.net/3Kvqh/1/ Simply browse to the bottom of the page and hit ‘toggle’, and watch the scroll be weird.

Further testing reveals that this only occurrs in Chrome. The plot thickens.

  • 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-11T16:22:36+00:00Added an answer on June 11, 2026 at 4:22 pm

    After better looking at my other answer, I think it will work for the first time but fail when you execute it a second time. So I’ve take a different approach here, this code will always work fine:

    <button onclick='javascript:hd=$(".panel:hidden");vi=$(".panel:visible");hd.toggle();vi.toggle();'>Toggle!</button>
    

    I’m taking advantage of jquery visibility filters to always firstly toggle the hidden divs later the visible ones.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.