...

View Full Version : Another way to stopPropagation in Moz ?



archimede
12-26-2004, 09:21 AM
Here is the problem

function action(a) {
alert("Hi" a.id)
}

<ul>
<li id="x" onmousedown="action(this)">Good Morning
<ul>
<li id="y" onmousedown="action(this)">Hello</li>
</ul>
</li>
</ul>

If I click on Hello I will have two message alert instead of one
Hi Y and Hi X
Now If I want to have just Hi Y if have to stopPropagation but in mozilla
the event is a kind of variable e and it seems in this case not easy to stop it

If found a solution which look as such:

function action(a) {
var name=a
document.onmousedown=callAlert
}

function callAlert() {

alert("Hi" + name.id)
}

Have you another solution or suggestion for this problem ?

Thanks in advance

Archimede.

jkd
12-26-2004, 06:54 PM
function action(event, a) {
alert("Hi " + a.id);
event.stopPropagation();
}

And then do:
onmouseover="action(event, this)"

Alternatively:

function action(event) {
alert("Hi " + event.currentTarget.id);
event.stopPropagation();
}

And just do:
onmouseover="action(event)"

archimede
12-26-2004, 06:59 PM
I found the way mozilla manage the event

in my exemple instead of writing mousedown="action(this)" I have to write mousedown="action(event,this)"

and in action

function action (e,a) {

e.stopPropagation()

alert("hi" + a.id)

}

You couldn't write event.stopPropagation as event work as this. Event contains the event information send by an event.

jkd
12-26-2004, 11:47 PM
You replied with exactly what I posted with? There is no problem with labelling the argument "event" either. It's just an identifier, like any other.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum