I want the radio input disabled by default. But its not working.
$(document).ready(function() {
$('input').attr('disabled', true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<form>
<input type="radio" name="harvest" id="first"> First
</form>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
I tried the following also:
$('input[type=radio]').attr('disabled', true);
$('#first').attr('disabled', true);
CodePudding user response:
$(document).ready(function() {
$('input[name=harvest]').prop('disabled', true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<input type="radio" name="harvest" id="first"> First
</form>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
Only 1 issue on you jQuery code, didn't close properly. Use specific ID $('#first') or class to refer the input field you want to disable. Using $('input') will disable all the input field. For more details please check https://www.w3schools.com/jquery/jquery_syntax.asp
$(document).ready(function() {
$('input').attr('disabled', true);
} ); /* Didn't close properly on your code*/
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<form>
<input type="radio" name="harvest" id="first"> First
</form>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>