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 5 of 5
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    binding value-passing event handlers to a collection of elements

    I want to bind event-handlers to each item in a complex list. What I'm doing at the moment is such a hack I'm almost embarrased to post it .... this:
    Code:
    tree = document.getElementById('list');
    data = tree.innerHTML;
    data = data.replace(/<li/ig,'<li onmouseover="openMenu(this,false)"');
    tree.innerHTML = data;
    I told you it was a hack But it works .. that much is certain.

    Is there a better way? I can't see how elm.onevent or addEventListener could be used, because they can't pass values. What else can I do?

    I need an x-browser solution, by which I mean moz, safari/konqi, O7 and IE5. I don't mind if it takes a different approach for each one ... or even if there's a better way for the others and I still have to use this hack for IE.

    Any improvement would be welcome; this method is a big onload process overhead I could well do without.
    Last edited by brothercake; 03-24-2003 at 07:04 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Yes they can...

    do
    element.onevent=function(){fnSomething(this,that);return(false||true);}
    instead of
    element.onevent=fnSomething;

    'this' will be a reference to the element in question.



    I think you forget that the html attribute value string acts as the block of a javascript function - so, the contents of the attribute value equates to the contents of the function block in JavaScript.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh .. yes ... thanks for the reminder Presumably from that I can extract the event as this.event ?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #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
    If you're not going to explicitly pass the event object (why not?), you can always go

    arguments.callee.caller.arguments[0]

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by jkd
    If you're not going to explicitly pass the event object (why not?), you can always go

    arguments.callee.caller.arguments[0]
    Oh, as in fnSomething(event) ...
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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