Results 1 to 3 of 3

Thread: Multiple events one function

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default Multiple events one function

    The following works with no problem:

    Code:
    element.oninput = go;
    element.onchange = go;
    ...
    But isn't there a shorter way to achieve the same result? Do we have to repeat the same line for each event?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In ordinary javascript:

    Code:
    element.oninput = element.onchange = go;
    If using recent versions of jQuery (with the newer 'on' function):

    Code:
    $(element).on('input change', go);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Rain Lover (05-14-2014)

  4. #3
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by jscheuer1 View Post

    Code:
    element.oninput = element.onchange = go;
    Thanks for the answer! I never thought it could be so simple.
    onchange is added to support IE and oninput for other browsers to handle <input type="range">. Does the events order make any difference?

Similar Threads

  1. multiple onload and onchange events plus...
    By gwmbox in forum JavaScript
    Replies: 9
    Last Post: 07-08-2011, 02:06 PM
  2. Replies: 2
    Last Post: 01-14-2011, 06:23 AM
  3. multiple onmouseover events
    By rich1234 in forum JavaScript
    Replies: 4
    Last Post: 10-07-2008, 03:10 AM
  4. Using multiple onMouseOver Events
    By schmiford in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 08-14-2007, 03:40 PM
  5. Multiple onclick events
    By fambi in forum JavaScript
    Replies: 5
    Last Post: 03-30-2006, 05:01 PM

Bookmarks

Posting Permissions

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