Overlapping divs with onclick properties

A

Adam

Hi all,

If two overlapping divs each have an onclick property, is there a way
to prioritize which one is called using javascript?

To put this in context, I'm making a simple HTML calendar. A day is
displayed as a div element with an onclick property that opens a "new
event" div (via Ajax). An event is shown as a div element within a day
element which has an onclick property to show event details. However,
when I click an event, both the event onclick and the day onclick
functions are called. Thus it is not possible to only view event
details without creating a new event. Is there a way to suppress the
onclick function of the element underneath?

Many thanks,
Adam
 
J

Joost Diepenmaat

Adam said:
Hi all,

If two overlapping divs each have an onclick property, is there a way
to prioritize which one is called using javascript?

To put this in context, I'm making a simple HTML calendar. A day is
displayed as a div element with an onclick property that opens a "new
event" div (via Ajax). An event is shown as a div element within a day
element which has an onclick property to show event details. However,
when I click an event, both the event onclick and the day onclick
functions are called. Thus it is not possible to only view event
details without creating a new event. Is there a way to suppress the
onclick function of the element underneath?

As I said earlier this week:

http://www.quirksmode.org/js/events_order.html

I tend to use something like:

function cancelEvent(e) {
e = e || window.event;
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
return false;

}

someElement.onSomeEvent=cancelEvent;
 
S

SAM

Adam a écrit :
Hi all,

If two overlapping divs each have an onclick property, is there a way
to prioritize which one is called using javascript?

Is there a way to suppress the
onclick function of the element underneath?

<http://www.captain.at/howto-addeventlistener-attachevent-parameters.php>

I don't understand very well, I'ven't no problem with :

<div style="position:relative">
<a style="display:block;position:absolute;border:1px
solid;width:200px;height:100px"
href="p1.htm" target="_blank"
onclick="alert('behind');return false;">blabla 1</a>
<a style="display:block;position:absolute;border:1px
solid;width:200px;height:100px"
href="p2.htm" target="_blank"
onclick="alert('at front');return false;">blabla 2</a>
</div>


the second one that covers the first is alone to fire.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top