apro
apro

Reputation: 31

How to toggle 2 divs on a click of a button?

Basically, i want to toggle an image with a flash file on click of a button. I want to show image in the beginning but want it to replaced by flash file. Also, i want the original image to show again on the click of the same button..

Upvotes: 3

Views: 2880

Answers (2)

alex
alex

Reputation: 490607

var container = $('#container'),
    image = container.find('img'),
    flash = container.find('object'),
    button = $('#my-button');

image.hide();

put_flash_in();

button.click(function() {

   if (image.is(':visible')) {
       image.hide();
       flash.show();
   } else {
       image.show();
       flash.hide();
   }

});

jsFiddle.

Upvotes: 3

LukLed
LukLed

Reputation: 31882

Something like this should work:

<div>
   <div id="image" style="display:block;">PLACE IMAGE HERE</div>
   <div id="flash" style="display:none;">PLACE FLASH HERE</div>
</div>

<div onclick="$('#image').toggle();$('#flash').toggle()">click me</div>

Upvotes: 3

Related Questions