Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorGavrilenko/d5bdb1f1a23b5616ab8427c90cec3e20 to your computer and use it in GitHub Desktop.
Save IgorGavrilenko/d5bdb1f1a23b5616ab8427c90cec3e20 to your computer and use it in GitHub Desktop.
активный элемент по клику
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