Last active
October 12, 2023 12:30
-
-
Save IgorGavrilenko/d5bdb1f1a23b5616ab8427c90cec3e20 to your computer and use it in GitHub Desktop.
активный элемент по клику
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelectorAll('.row').forEach((currentRow,index,rows)=>{ | |
currentRow.addEventListener('click',()=>{ | |
rows.forEach((row)=> row.classList.remove('active')); | |
currentRow.classList.add('active'); | |
}) | |
}) | |
<table> | |
<tbody id="body_table"> | |
<tr class="row" data-id="1"> | |
<td class="name ">Смородина Алена</td> | |
</tr> | |
<tr class="row " data-id="2"> | |
<td class="name">Коновалов Александр</td> | |
</tr> | |
<tr class="row " data-id="3"> | |
<td class="name">Зайченко Валентина</td> | |
</tr> | |
</tbody> | |
</table> | |
// //////////////////////////// | |
$(activeItem); | |
function activeItem(){ | |
var $item = $('.item'), | |
$ItemActiveClass = 'item--active'; | |
$item.each(function(a){ | |
$(this).on('click', function() { | |
$item | |
.removeClass($ItemActiveClass) | |
.eq(a) | |
.addClass($ItemActiveClass); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment