0

I'm using this code in my html page. when clicking on the image "photo_medias", the image disappears and the video iframe displays. It works fine, but I would like to make a jQuery function with this code. I don't want to have JavaScript inside my HTML. Can anybody help me with this?

<li class="mix videos">
    <div onclick="this.nextSibling.style.display='block'; this.style.display='none'">
        <img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg" class="photo_medias" style="cursor:pointer" />
    </div>
    <div style="display:none">
        <iframe class="youtube"  src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>" frameborder="0" allowfullscreen></iframe> 
    </div>
</li>
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
mmdwc
  • 1,095
  • 6
  • 27
  • 53

1 Answers1

0

You can do

Fiddle Demo

$('.mix.videos div').click(function () {
    $(this).hide().siblings().show();
});


or

Fiddle Demo

$('.mix.videos div').click(function () {
    $(this).hide();
    next_el = $(this).next().length ? $(this).next() : $(this).closest('.mix.videos').children().first();
    next_el.show();
});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107