fix exception on table element click
This commit is contained in:
parent
ce17037475
commit
1af4941b68
1 changed files with 10 additions and 3 deletions
|
|
@ -961,9 +961,16 @@
|
||||||
<script>
|
<script>
|
||||||
document.querySelectorAll('table.interactive').forEach(element => {
|
document.querySelectorAll('table.interactive').forEach(element => {
|
||||||
element.addEventListener('click', (event) => {
|
element.addEventListener('click', (event) => {
|
||||||
const row = event.path.find(element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY');
|
const highlightedClass = 'highlighted';
|
||||||
if (row) {
|
const isRow = element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY';
|
||||||
row.classList.toggle('highlighted');
|
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);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue