jquery - replace src and back on click event -


this function go through images:

var src = event.target.src;         popupimageelem.src = (src);         //popupimageelem.src = src.replace('/thumb/','/big/');         tweenlite.to([overlayelem, popupelem], .5, {opacity: 1, visibility: 'visible'});         $(document).on('click','.left-button',(e) => {             var srcprev = this.viewmodel.getprevthumbnailbysrc(popupimageelem.src);             popupimageelem.src = (srcprev);             //popupimageelem.src = srcprev.replace('/thumb/','/big/');         });         $(document).on('click','.right-button',(e) => {             var srcnext = this.viewmodel.getnextthumbnailbysrc(popupimageelem.src);             popupimageelem.src = (srcnext);             //popupimageelem.src = srcnext.replace('/thumb/','/big/');         }); 

i want change image src /thumb/ /big/ when click next has go /thumb/ again when go next image , when on next image should change /temp/ /big/ again.

if unquote commented code replaces doesn't change wont finding next image since works on url contains /thumb/

if using jquery 1.8 or previous version, should may take @ jquery basic .toogle() allowed make :

$( "#target" ).toggle(function() {     alert( "first handler .toggle() called." ); }, function() {     alert( "second handler .toggle() called." ); }); 

however, since it's removed jquery 1.9, can create own little plugin : come felix kling --> here , work me.

(function($) {     $.fn.clicktoggle = function(func1, func2) {         var funcs = [func1, func2];         this.data('toggleclicked', 0);         this.click(function() {             var data = $(this).data();             var tc = data.toggleclicked;             $.proxy(funcs[tc], this)();             data.toggleclicked = (tc + 1) % 2;         });         return this;     }; }(jquery)); 

Comments