Javascript Click event not firing when clicking on an element's padding
Asked Answered
S

3

8

Has anyone ever experienced a similar thing? When I click on the middle area of an li element, the click event fires, but when clicking on the padded area towards its edge the event doesn't fire.

I'm binding to click on the element.

Super stumped.

Spellbound answered 22/2, 2012 at 15:51 Comment(6)
are you sure it's not margin you are talking about?Pteridology
Chrome doesn't do anything weird: jsfiddle.net/G8uRH.Languishing
Which browser(s)? Might be by designVat
@IanStormTaylor can you reproduce it in jsFiddle ?Vituperate
Post your code or a jsFiddle.Famagusta
I'm having the same issue, with the same HTML element (li), in Google Chrome 22. Is this a thing?Penicillin
P
1

This is no solution, just a workaround, but wrap the whole content of an li in a wrapper div. Apply your padding to the div and not the li. This solved my issue, but this still seems like a very weird bug to me.

Penicillin answered 19/10, 2012 at 17:5 Comment(0)
E
1

I also saw this happening, but only on iOS. Wrapping with a div didn't work either. After some research I discovered that the YUI delegate listener was not firing on that node's padding (though it did everywhere else on the node). Ultimately, I fixed it by removing that node from the delegate listener entirely and adding a traditional click event listener for just that node. After that, it worked fine!

Not sure if this will help your situation or not.

Entophyte answered 10/1, 2013 at 16:2 Comment(0)
H
1

Just had this problem in Chrome, fixed it by adding position: relative; to the element.

Haeckel answered 24/7, 2021 at 3:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.