I wanted to ask about using selector from a variable
first I have:
function check()
{
$('.info input, .info select').each(function(n, element){
if ($(element).val()=='')
alert('empty');
});
}
and called it in
$('input')change(check);
and they worked fine.
But now I want to pass some value to the function to make it dynamic, like
$('input')change(check('.info'));
and changed the function to
function check(sel) {
$(sel +' input, '+ sel + ' select').each(function(n, element){
if ($(element).val()=='')
alert('empty');
});
}
but it doesn't work. Any help please.. Thanks,
nagut
change should get a function. By writing check('.info') you are triggering the function, and passing its result to the change event. Simply wrap the call in another function:
$('input').change(function(){check('.info');});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With