framara
framara

Reputation: 2963

HTML. When there's 2x onclick event in the same area

here's the situation: I have a where in every cell all the area has a onclick event that opens a edit form, let's call this A. In the same cell, in a corner I also have an 'X' to delete the object represented in that cell, also with an onclick event in this case with a Yes/No warning, let's call this B.

When I click on the X (onclick B), it appears de dialog to confirm I want to delete or not but the problem comes whatever I trigger, I also run the onclick A because B is in the same onclick area that A.

Is there any solution so when I click on B, A does not trigger? Hope I make clear my problem.

Thanks

Update

Thanks to the guide http://www.quirksmode.org/js/events_order.html I just had to add this JS function

function doSomething(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}

And call it on the onclick B event before calling my other function:

onclick="doSomething(); Calendar.delClick('${id}', this); return false"

Thank you both very much ;)

Upvotes: 1

Views: 283

Answers (2)

anddoutoi
anddoutoi

Reputation: 10111

I think what you experiencing is event bubbling. Have a look at PPKs excellent writing in this matter.

Upvotes: 2

N 1.1
N 1.1

Reputation: 12534

Use event bubbling

Upvotes: 4

Related Questions