Answer the question
In order to leave comments, you need to log in
Async between two divs in js?
hello there is a structure
<div class="wrapper1">
<div class="wrapper1-item active"></div>
<div class="wrapper1-item"></div>
<div class="wrapper1-item"></div>
<div class="wrapper1-item"></div>
<div class="wrapper1-item"></div>
</div>
<div class="wrapper2">
<div class="wrapper2-item active"></div>
<div class="wrapper2-item"></div>
<div class="wrapper2-item"></div>
<div class="wrapper2-item"></div>
<div class="wrapper2-item"></div>
</div>
Answer the question
In order to leave comments, you need to log in
<div class="wrapper1">
<div class="wrapper1-item active">1</div>
<div class="wrapper1-item">2</div>
<div class="wrapper1-item">3</div>
<div class="wrapper1-item">4</div>
<div class="wrapper1-item">5</div>
</div>
<div class="wrapper2">
<div class="wrapper1-item active">1</div>
<div class="wrapper1-item">2</div>
<div class="wrapper1-item">3</div>
<div class="wrapper1-item">4</div>
<div class="wrapper1-item">5</div>
</div>
<script>
'use strict';
var w1 = document.querySelector('.wrapper1'),
w2 = document.querySelector('.wrapper2');
[].forEach.call(w1.children, function(i,ind) {
i.ind = ind;
});
[].forEach.call(w2.children, function(i,ind) {
i.ind = ind;
});
w1.addEventListener('click', function (e) {
var t = e.target;
if(t.ind === undefined) return;
[].forEach.call(w2.children, function(i) {
i.classList.remove('active');
});
w2.children[t.ind].classList.add('active');
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question