Hide show div front and back per div behaviour function/toggle jquery -


i want create sort of toggle between 2 div's classes: front , back. both in .entry-footer. it's wotking allright. last step needs correct normal : front visible, hidden... , not backs should hidden klikobj (=clikobject).... suggestions optimize code?

https://jsfiddle.net/ontwerp73/osg8up7a/2/#&togetherjs=uojqmsnd2f

$('.entry-footer').on('click', function(event) {      var klikobj = event.target;      $(klikobj).closest('.front').hide();      $(klikobj).next('.back').show();      $('.back').on('click', function(event) {          $(klikobj).closest('.front').show();          $(klikobj).next('.back').hide();      });  }); 

the html base :

<footer class="entry-footer"> <div class="front" style="display: block;"> <br>titel: mr robot<br>regisseur: mr bean<br>producent: spielberg<br>info: extra! extra! extra! extra! <br>productiejaar: 2017              </div> <div class="back" style="display: none;"> <br>beschrijving: een robot een programmeerbare machine die verschillende taken uit kan voeren. hierin verschilt hij van een numerieke machine, die geprogrammeerd voor één taak. in de praktijk betekent....</div> </footer> 

why not use toggle() function?

$('.entry-footer').click(function() {   $(this).children().toggle(); }); 

the working version multiple divs:

$('.entry-footer').click(function() {      var childnum = $(this).children().length;     $(this).children().each(function(ind, el) {         if ($(this).is(':visible')) {             if (ind == childnum - 1){                 $(this).siblings(":first").show();                 $(this).hide();                 return false;             } else {                 $(this).hide();                 $(this).next().show();                 return false;             }        }    }); }); 

jsfiddle


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -