Lawrence
Lawrence

Reputation: 845

Event bubbling or failed bubbling on click event in javascript

My basic issue is that I have a click event that i have attach to my container, i am trying to delgate that click event just to the buttons in that container. All of that is easy, the issue i have is the event.target in webkit is hitting the spans in the button instead of the button its self. How do i stop the click event from bubbling down wards to the span in the button. I want my targ to be the butto. here is a quick demo showing the issue fiddle of the issue

Upvotes: 0

Views: 110

Answers (1)

Rui Carneiro
Rui Carneiro

Reputation: 5671

I have no idea if it is possible to disable event bubbling is this case.

However in these cases I make a inverted event bubbling:

while(targ != null) {
    if (targ.nodeName.toLowerCase() === 'button') {
        alert(targ.nodeName.toLowerCase());
        break;
    }

    targ = targ.parentElement;
}

Fiddle: http://jsfiddle.net/jVeMw/1/

Is not perfect for performance but since you are restricting the click event to the vidCommentBoard div it should not be a problem.

Upvotes: 1

Related Questions