Home > Net >  Not Able to Set Attribute of a Checkbox When It has Space in It's Value Attribute
Not Able to Set Attribute of a Checkbox When It has Space in It's Value Attribute

Time:05-26

Having space between string in Value of a checkbox input like Item Two I am not able to set the checkbox to be checked.

<input type="checkbox" id="item2" name="check" value="Item Two">Item Two
$(":checkbox[value=Item Two]").prop('disabled', true);

Is there any way to fix this without changing the value of the input?

$(":checkbox[value=ItemOne]").prop("checked", "true");
$(":checkbox[value=Item Two]").prop('disabled', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="item1" name="check" value="ItemOne">Item One
<input type="checkbox" id="item2" name="check" value="Item Two">ItemTwo

CodePudding user response:

You must quote the value if it has spaces

$(':checkbox[value="Item Two"]').prop('disabled', true);
  • Related