Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking a child doesn't trigger the parent's :active state in IE

I have found an irritating bug in IE 8-10 that prevents a parent's active state being triggered. It appears that if a child of the parent element is the target of the click event the active state on the parent element is not triggered.

Here is a working example. If you click the text inside the <li> the element wont change colour. If you click inside an <li> anywhere other than on the <p> child the element will turn blue.

This is a problem as it pretty much renders the css :active pseudo state useless in IE if the element has any children.

Has anyone encountered this problem before, and even better found a way round it?

like image 318
wilsonpage Avatar asked May 25 '12 10:05

wilsonpage


People also ask

How do you only trigger parent click event when a child is clicked?

To only trigger parent click event when a child is clicked with JavaScript, we call stopPropagation . parent. addEventListener( "click", (e) => { e. stopPropagation(); console.


1 Answers

Here's an easy workaround: add a css rule to the paragraph.

Working example

CSS

ul { list-style: none; }
li { height: 50px; margin-bottom: 4px; background: red; }
li:active { background: blue; }
p:active { background: blue; height: 100%;}
like image 107
Itay Gal Avatar answered Nov 16 '22 01:11

Itay Gal