If I interpret the question correctly, you can pass an HTML string response
to jQuery()
to create a jQuery object from the HTML string, then call .attr("name")
and .prop("checked")
:
var input = $(response).find("input");
console.log(input.attr("name"), input.prop("checked"));
How do I get the input name (gender)? And whether the checkbox is
checked out not?
If you are trying to get the .name
and .checked
property values of clicked element you can call .querySelector()
chained to this
: .checkbox
element, with selector "input[type=checkbox]"
; .getAttribute()
with "name"
as parameter, .replace()
with RegExp
/^\w+\[|\]/g
to get word within "["
, "]"
; and .checked
property of the matched element returned by .querySelector()
$(".checkbox").click(function () {
var input = this.querySelector("input[type=checkbox]");
var _name = input.getAttribute("name").replace(/^\w+\[|\]/g, "");
var checked = input.checked;
console.log(_name, checked);
$.ajax(/* settings */);
});