Link to home
Start Free TrialLog in
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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maqskywalker
maqskywalker

ASKER

Thanks.
Thanks for points