Combining two event handlers into one (jquery)

531 views javascript
1

I have extracted a function from two event handlers, however I was wondering if the event handlers themselves could be combined:

// when to hide/show the Submit link (select is changed)
$('.season select').on('change', function() {
    var TVContainer = $(this).parents('.submission');
    getTVData(TVContainer);
});

// when to hide/show the Submit link (validate on input changed)
$('.season input').on('keyup', function() {
    var TVContainer = $(this).parents('.submission');
    getTVData(TVContainer);
});

answered question

1 Answer

6

You could extract your handlers to another function:

function handler () {
    var TVContainer = $(this).parents('.submission');
    getTVData(TVContainer);
}

$('.season select').on('change', handler);

// when to hide/show the Submit link (validate on input changed)
$('.season input').on('keyup', handler);

posted this

Have an answer?

JD

Please login first before posting an answer.