Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Using jQuery with multiple events as variable

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #201757
    Shikkediel
    Participant

    Anything that could be incorrect or a pitfall with doing that (see title)? I can’t find anything on it on the web but it seems to work and could optimise the code nicely when there’s a lot of events being handled.

    For example :

    var press = 'mousedown touchstart',
    release = 'mouseup touchend';
    
    $('#someDiv').on(press, function() {
    
        // do stuff
    
        $(this).off(release).on(release, function() {
    
        // other stuff
    
        });
    });
    

    A penny for your thoughts…

    #201781
    Shikkediel
    Participant

    Okay, thanks. That’s pretty neat – I’ll be using it then whenever it might be useful (why didn’t I think of it before).

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.