www.webdeveloper.com
Results 1 to 5 of 5

Thread: anonymous function as event handler

  1. #1
    Join Date
    Apr 2011
    Posts
    27

    anonymous function as event handler

    Hi all,

    How can I make "22" to be displayed in IE
    <html>
    <head>
    <script type="text/javascript">
    alert("11");
    document.ondblclick=f16;
    alert("22");
    var f16=function(){ alert("f16") }
    </script>
    </head>
    <body>
    </body>

    TIA
    -s

  2. #2
    Join Date
    Apr 2011
    Posts
    27
    looks like var f16=function f16()(} works. Any better way?

  3. #3
    Join Date
    Apr 2011
    Posts
    27
    Thought it should work but doubleclicking doesn't bring up "f16" in firefox although works in ie. how can i use a double click event handler in a format like
    var f16=function ???();

    Thanks.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    If you intend to declare a function as a variable, you should declare it before you attach an event which will fire that function:
    Code:
    <script type="text/javascript">
    var f16=function(){ alert("f16") }
    document.ondblclick=f16;
    </script>

  5. #5
    Join Date
    Apr 2011
    Posts
    27
    Thx.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles