How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?
var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);
How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?
var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);
Try this
var name="Jack";
$("input[type=radio][name="+name+"]").attr('disabled', true);
You have to use quotes around your attribute selector value. Further, name=name
does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):
const name = "foo"
console.log(document.querySelector(`input[type="radio"][name="${name}"]`))
<input type="radio" name="foo" />
<input type="radio" name="bar" />