2

I have following function in my onRender function, which will be called when the findall checkbox is clicked.

this.$el.find('.findall').on('click', function(e) { ...  });  

I want to know how can I write a function simillar to above which should be called if the checkbox is checked. (by default I am checking this checkbox, but the above function will be called only when I click that box, but I need something that will called based on the checkbox status).

2 Answers 2

1

You may try this:

this.$el.find('.findall').on('change', function(e)
{
    if($(this).is(':checked'))
    {
        // Do your job here...
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. But this will be called when there is change. I want this function to be called onload of that checkbox.. This function should be called when the checkbox is displayed without requiring any change or click.
Then use $(document).ready(...) and use $('.findall :checked').
0

If you want to do different actions depending on whether an item is checked or not:

this.$el.find('.findall').each(function () {
    if ($(this).is(":checked")) {
        // do action for checked
    } else {
        // do action for not checked
    }
});

If you want to do actions only on each checked checkbox:

this.$el.find('.findall :checked').each(function () {
        // do action for checked
});

Or if you want to do it on page load:

$(function () {
    $('.findall').each(function(){
        if ($(this).is(":checked")) {
            // do action for a checked checkbox
        } else {
            // do action for an unchecked checkbox
        }
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.