webvitaly
webvitaly

Reputation: 4271

How to checked checkbox which is loaded thru ajax?

This method does not work because checkbox is not in the DOM:

$('input[type=checkbox][name=rememberme]').prop('checked', true);

I don't know how to use .on() because I do not need to bind event:

$(elements).on( events [, selector] [, data] , handler );

How to checked checkbox which is loaded thru ajax using jQuery?

Upvotes: 4

Views: 1364

Answers (2)

user5296864
user5296864

Reputation:

$( document ).ajaxComplete(function() {
  $('input[type=checkbox][name=rememberme]').prop('checked', true);
});

Try this:

Upvotes: 5

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

try doing like, on your ajax response, get the checkbox and set it to checked, like:

var cBox = $($.parseHTML(your_ajax_response_data)).filter("input[name='rememberme']");
cBox.prop('checked', true);

Upvotes: 1

Related Questions