How to execute .off () action .on () with different selectors

Link to the code here - http://jsfiddle.net/V5g2m/

var $template = $('div.main');

$template.off('change.filterIt', 'select.filter')
    .on('change.filterIt', 'select.filter', function(){
    alert(1);
});

$template.off('change', 'select.filter[name="source"]')
    .on('change.getNewSource', 'select.filter[name="source"]', function(){
    alert(2);
});

Can someone help me with my question - how to cancel the change.filterIt event only from this select.filter [name = "source"] selector . It should remain on the other select.filter elements, but not run on current.

+4
source share
1 answer

Filter it with :not()before adding event

var $template = $('div.main');

$template.off('change.filterIt', 'select.filter')
.on('change.filterIt', 'select.filter:not([name="source"])', function(){
    alert(1);
});

$template.off('change', 'select.filter[name="source"]')
    .on('change.getNewSource', 'select.filter[name="source"]', function(){
    alert(2);
});

Fiddle

0
source

All Articles