var elements = document.querySelectorAll('.someElement');
var prevElement;
[].forEach.call(elements, function(element) {
element.addEventListener('click', function(e) {
var currentElement = e.сurrentTarget;
if (/* some condition with currentElement and prevElement */) {
// do something
}
prevElement = currentElement;
});
});
<div id="items">
<div>A</div>
<div>B</div>
<div>A</div>
<div>B</div>
</div>
{
let prevItem = '-'
items.addEventListener('click', e => {
let currentItem = e.target.innerText
// Выводим предыдущее, текущее и true/false если равно/не равно
console.log(prevItem, currentItem, prevItem === currentItem ? true : false)
prevItem = currentItem
})
}