I'm having two jquery's that I run and I want to combine them both in the same line. Here's an example of what i'm trying to do.
$(function(){
$('input').each(function(){
if ($(this).is(':checked')) {
$(this).after('this is checked');
}
});
$('input').click(function(){
if ($(this).is(':checked')) {
$(this).after('this is checked');
}
});
});
Now, both functions do the same thing, one is executed for checking if there are any inputs being checked from the backend, the other one just responds to user clicks.
I was thinking if i can combine them in a statement like this,
$('input').bind('each click');
but i noticed that even this wouldn't work with each. Any ideas?
Thanks!
Just name the function..
function handler() {
if ($(this).is(':checked')) {
$(this).after('this is checked');
}
}
then use it in both situations:
$(function(){
$('input').each(handler);
$('input').click(handler);
});
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