If you want to link these conditionally in the most elegant, shortest way, you can do this:
var $formSearch = $('form#search'), hideShow = function () { if ($(this).val() == '') { $('a#clear').hide(); } else { $('a#clear').show(); } }; $formSearch.find('input').on('keyup', hideShow); $formSearch.find('select').on('change', hideShow);
If you want both events to fire for both selectors, you can do this. Perhaps this will be normal, as you may want them to be running anyway.
$('form#search input, form#search select').on('keyup change', function() { if ($(this).val() == '') { $('a#clear').hide(); } else { $('a#clear').show(); } });
source share