2

I am adding some checkbox to the page through ajax how to bind the click and change function for these checkboxes my script is here

$(document).delegate("#filterOptions input[name=inNeedAmountRange]").bind("click change", function () {
    var elementValue = $(this).val();
    if ($(this).is(':checked')) {
        alert('checked : ' + elementValue);
    }
} else {
    alert('Not checked :' + elementValue);
}
});
2
  • The answers below both suggest using the .on method, but that will depend on the version of jQuery you are using. Are you using jQuery 1.7 or later? Commented Feb 11, 2014 at 4:54
  • @AnthonyVeach yes I am using jQuery 1.7 only Commented Feb 11, 2014 at 4:59

2 Answers 2

14

Try .on()

Fiddle Demo

$(document).on("click change", "#filterOptions input[name=inNeedAmountRange]", function () {
    var elementValue = this.value;
    if ($(this).is(':checked')) {
        alert('checked : ' + elementValue);
    } else {
  // ^ remove extra }
        alert('Not checked :' + elementValue);
    }
});

Event Delegation

Sign up to request clarification or add additional context in comments.

Comments

3

Try: http://api.jquery.com/on/

$(document).on("change click", ""#filterOptions input[name=inNeedAmountRange]", function() {
    //do something
});

You can replace document with any static container.

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.