ComputerWolf / SlickNav

Responsive Mobile Menu Plugin for jQuery
MIT License
939 stars 314 forks source link

Slicknav and dropdownmenus based on a select with jquery on('change… #25

Closed ebiasini closed 10 years ago

ebiasini commented 10 years ago

We are trying to make slicknav load a subsitute for a select which fires the page change using the following code:

$('.switcher').on('change', function () { var url = $(this).val(); // get selected value if (url) { // require a URL window.location = url; // redirect } return false; });

Even though slicknav gets the same class as it's original counterpart, the change event doesn't seem to occur, so the page doesn't change.

ComputerWolf commented 10 years ago

This is because .on only can bind to elements that already exist on the page. SlickNav creates the new element and inserts it into the DOM so you will have to modify the code a bit.

$(document).on('change', '.switcher', function () {
    var url = $(this).val(); // get selected value
    if (url) { // require a URL
        window.location = url; // redirect
    }
    return false;
});