Avatar of maqskywalker
maqskywalker
 asked on

jquery page load event

Hi experts,

I'm using jQuery on a html page.
I'm using this version of jQuery  http://code.jquery.com/jquery-1.10.1.js

In my page jquery code I have this code.
This code shows a div called #div1 whenever the page load.

    // after page refresh this fires
    $(window).load(function() {
     //insert all your ajax callback code here.
     //Which will run only after page is fully loaded in background.
                        
                // show div called div 1 on page load
            $("#div1").show();      
    });



On my page i have two divs. One has id="div1" and the other has id="div2".

Is there a way to do this?:

On the very first page load show #div1.

On the 2nd page load or any other page load after the 2nd page load show #div2 and hide #div1
jQuery

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
Julian Hansen

On the 2nd page load
What do you mean by page load? Does this mean a page refresh (F5?)

If so you are resetting state so if you want the behaviour you are describing you need to maintain some sort of state to say what has happened in the past.

My question is if you are going to do this (maintain state) then why not simply have the the server process either render out div1 or div2 depending on the state?

I suspect I am not understanding your requirement entirely - please can you elaborate a bit more.
ASKER CERTIFIED SOLUTION
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
maqskywalker

ASKER
Thanks.
Marco Gasi

Thanks for points
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck