Reputation: 1
I've been driving myself nuts trying to get a radio button to be disabled in a form that is generated dynamically. This is the code that I am using. What is throwing an error is the ID name because of all the brackets in it. I tried escaping them but to no avail.
The script:
$(document).ready(function() {
$("div.property_options_select input[id='#akID\\[114\\]\\[atRadioOptionID\\]\\[\\]1']").on('click',function(){
$("input:radio").attr('disabled',true);
});
});
The html:
<div class="property_options_select">
<label class="radio">
<input type="radio" name="akID[114][atRadioOptionID][]" id="akID[114][atRadioOptionID][]1" value="17" class="ccm-input-radio" /> 9:00AM - 11:00AM </label>
<label class="radio">
<input type="radio" name="akID[114][atRadioOptionID][]" id="akID[114][atRadioOptionID][]2" value="18" class="ccm-input-radio" /> 9:30AM - 11:30AM </label>
Anyone have a suggestion how to target that first radio button?
Upvotes: 0
Views: 328
Reputation: 2725
You have to use the double slash inside a jquery selector.
$(document).ready(function() {
$("div.property_options_select input[id='#akID\\[114\\]\\[atRadioOptionID\\]\\[\\]1']").on('click',function(){
$("input:radio").attr('disabled',true);
});
});
Upvotes: 0
Reputation: 874
You don't need to escape the brackets. You just need to remove the #
.
Your selector will be $("div.property_options_select input[id='akID[114][atRadioOptionID][]1']")
https://jsfiddle.net/3h4jpm1e/
Upvotes: 0
Reputation: 1
You tried with double backslash?
$('#akID\\[114\\]\\[atRadioOptionID\\]\\[\\]1').prop('disabled', true);
Upvotes: 0
Reputation: 4757
You can target the first child using the :first-child
selector like this:
$("input:radio:first-child").attr("disabled","disabled");
Upvotes: 1