How to set a checkbox that loads via ajax?

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

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

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

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

How to set a checkbox that loads via ajax using jQuery?

+4
source share
2 answers
$( document ).ajaxComplete(function() {
  $('input[type=checkbox][name=rememberme]').prop('checked', true);
});

Try the following:

+4
source

try to do, for example, when answering ajax, check the box and check it, for example:

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

Source: https://habr.com/ru/post/1544084/


All Articles