Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Another way to stopPropagation in Moz ?

    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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)"

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    the answer

    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.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •