question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct way to add multiple event listeners

See original GitHub issue

I have the following code and I’m trying to add multiple event handlers to a slider, but I keep getting the following error “namespacedEvent.split is not a function”… What is the correct way of doing this?

noUiSlider.create(testSlider, {
    start: 0,
    step: 1,
    range: {
        'min': 0,
        'max': 10,
    },
    format: {
        to: function (value) {
            return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        },
        from: function (value) {
            return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        },
    },
    }).on(
    {
        'slide': function (values, handle) {
            console.log("Slide Fired");
        }
    },
    {
        'end': function (values, handle) {
            console.log("End Fired");
        }
    }
);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
leongersencommented, Oct 9, 2019

Call on multiple times, like so:

noUiSlider.create(testSlider, ...);

testSlider.noUiSlider.on('slide', function() { ... });
testSlider.noUiSlider.on('end', function() { ... });
0reactions
github-actions[bot]commented, May 27, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

adding multiple event listeners to one element - Stack Overflow
const element = document.querySelector("#myId"); function handleEvent(e) { // do something } // I prefer string.split because it makes editing the event list ...
Read more >
Listening to multiple events in vanilla JS - Go Make Things
In vanilla JavaScript, each event type requires its own event listener. Unfortunately, you can't pass in multiple events to a single listener ...
Read more >
How to Add Event Listeners to Multiple Elements using ...
The process is the same, simply query for the element or elements, then add an event listener to each individual element. Hopefully, this...
Read more >
Chapter 4. Multiple Event Handlers: Two's company - O'Reilly
We need a way to assign more than one handler to an event, which means we can't just assign a handler to an...
Read more >
How to add an event listener to multiple elements in JavaScript
How to add an event listener to multiple elements in JavaScript ; document.querySelector · '.my-element' ; document.querySelectorAll · '.some-class' ; [document.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found