How to switch 2 divs at the click of a button?

Basically, I want to switch the image using a flash file with the click of a button. I want to show the image at the beginning, but I want it to be replaced by a flash file. In addition, I want the original image to be displayed again when I press the same button.

+3
source share
2 answers

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>
+3
source
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 .

+3
source

Source: https://habr.com/ru/post/1791764/


All Articles