Trevor Arjeski
Trevor Arjeski

Reputation: 2168

Using jQuery with toggle events

I'm using some jQuery UI for a div that toggles on and off the screen. On document load the div object is on the screen. It works great but I was wondering if there was a way to set it so that it is hidden on document load, then the user would have the ability to click a button to make it appear.

I tried having the function run on document.ready, but that didn't seem to work. Here is the code directly from the jQueryUI.

$(function() {
        // run the currently selected effect
        function runEffect() {
            // get effect type from 
            var selectedEffect = "slide";

            // most effect types need no options passed by default
            var options = {};
            // some effects have required parameters
            if ( selectedEffect === "scale" ) {
                options = { percent: 0 };
            } else if ( selectedEffect === "size" ) {
                options = { to: { width: 200, height: 60 } };
            }

            // run the effect
            $( "#effect" ).toggle( selectedEffect, options, 500 );
        };

        // set effect from select menu value
        $( "#button" ).click(function() {
            runEffect();
            return false;
        });
    });

Upvotes: 0

Views: 292

Answers (2)

Andbdrew
Andbdrew

Reputation: 11895

the CSS solution above is the right way, but if you feel like doing it with javascript...

$(function() {
    $("#effect").hide();
});

Upvotes: 1

Hussein
Hussein

Reputation: 42818

Put this in your CSS. This will set it to hidden by default.

#effect{
 display:none;
}

Upvotes: 3

Related Questions