Itering array with jquery each -


i have many video's each under slider. when video played , user has clicked slider, prevouis video must stop playing. i've following code that's working correctly.

$('#slidername1').on('hidden.bs.collapse', function () {     $('#video1').get(0).pause(); }) $('#slidername2').on('hidden.bs.collapse', function () {     $('#video2').get(0).pause(); })  

etc. etc.

now want use array sliders , video's , iterate e.g. jquery each. i've tried several options, didn't manage far. slider names specific names of video's, recognized. working solution?

don't use .each. give sliders class, e.g. class="slider" , bind $(".slider").

then put id of corresponding video in data-xxx attribute.

<div id="slidername1" class="slider" data-video="video1">...</div> 

then js can be:

$(".slider").on('hidden.bs.collapse', function() {     $('#' + $(this).data('video')).get(0).pause(); }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -