I have a basic list going on, with the HTML structure like this:
<ul class="list">
{...}
<li class="item">Ellipse</li>
{...}
Then I use some JS to add buttons to delete items, so the end structure is like this:
<ul class="list">
{...}
<li class="item">Ellipse <button>Delete item</button></li>
{...}
I also have a function to strike through the list elements on click by toggling a CSS class:
let ul = document.querySelector('.list');
{...}
function markAsDone (event) {
let target = event.target;
target.classList.toggle('done');
}
{...}
ul.addEventListener('click', markAsDone);
This works as expected (e.g. the list item is struck through). However, if I change the list items' display property to flex in CSS:
.item {
display: flex;
justify-content: space-between;
max-width: 300px ;
}
And then click on the item, the text of the button also is struck through, unlike before! Since I've started writing this, I no longer know which behaviour feels more 'wrong' to me, lol.
The full code is on Codepen here. Try clicking the items in the list, then uncomment the CSS style for .item to see what I mean.
My uneducated guess would be that the answer to this is in the way the flex containers treat the items in them. However, my understanding of it is very limited, so I've come to you for an answer.