1
0
mirror of https://github.com/jdan/98.css.git synced 2026-05-05 06:01:22 +09:00

fix exception on table element click

This commit is contained in:
J. Garay
2023-09-20 15:27:45 -03:00
parent ce17037475
commit 1af4941b68

View File

@@ -961,9 +961,16 @@
<script>
document.querySelectorAll('table.interactive').forEach(element => {
element.addEventListener('click', (event) => {
const row = event.path.find(element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY');
if (row) {
row.classList.toggle('highlighted');
const highlightedClass = 'highlighted';
const isRow = element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY';
const newlySelectedRow = event.composedPath().find(isRow);
const previouslySelectedRow = Array.from(newlySelectedRow.parentElement.children).filter(isRow).find(element => element.classList.contains(highlightedClass));
if(previouslySelectedRow){
previouslySelectedRow.classList.toggle(highlightedClass);
}
if (newlySelectedRow) {
newlySelectedRow.classList.toggle(highlightedClass);
}
})
});