mirror of
https://github.com/jdan/98.css.git
synced 2025-08-31 17:42:07 +02:00
Merge pull request #177 from jdan/fix-172-tableview-event-path-access
fix exception on table element click
This commit is contained in:
@@ -965,9 +965,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);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
Reference in New Issue
Block a user