treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Auto start jQuery function

  • I would like this pop-up to appear when the page loads. I don't want for a button to be pushed or any action like that.
    Is there like an auto run action?

    http://goodwynbuilding.com/test/


    $("#button").click(function(){
    //centering with css
    centerPopup();
    //load popup
    loadPopup();
    });


    Thanks
  • This should work:

    $(document).ready(function() {
    //function to open the popup
    })
  • I already have that.

    $(document).ready(function(){


    //LOADING POPUP
    //Click the button event!
    $("#button").click(function(){



    //centering with css
    centerPopup();
    //load popup
    loadPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function(){
    disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function(){
    disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
    disablePopup();
    }
    });

    });
  • Try taking out the first button click:
    $(document).ready(function(){        

    //centering with css
    centerPopup();
    //load popup
    loadPopup();

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function(){
    disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function(){
    disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
    disablePopup();
    }
    });

    });
  • Thanks that worked, but now I cant figure out why it has disabled these two...

    	$("#popupContactClose").click(function(){
    disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function(){
    disablePopup();
    });
  • not sure. Are you using a plugin? It might assign id's to objects on the first click, so now the id's aren't being assigned because there's no initial "click" action. Really am guessing on this on though. :/
  • Nevermind! I see I had to move the brackets out to include all.