Reputation: 17
I'm looking for a way in jQuery console to checkbox selected values in Chrome (ie. 416800-000). I have found ways to do it but my HTML situation is a bit different. Going off the name parameter isn't doable for me.
<input type="hidden" name="value[1].value" value="416800-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
The above value when type is hidden can by dynamic.
Here is a demo of my problem
https://jsfiddle.net/68ujpfrw/1/
Similar to this case Get checkbox with specific value
Edit: Also, is it possible to do find a text (ie. Admin) then do the checkbox?
<input type="hidden" name="value[1].value" value="416800-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
"Admin"
Upvotes: 1
Views: 390
Reputation: 12613
Well, since the actual/visible checkbox is after the hidden one then you can simply use .next()
and then set the attribute value.
$("input[value='416800-000']").next().prop("checked", true);
Updated the JSFiddle
$("input[value='416800-000']").next().prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="hidden" name="value[1].value" value="416800-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
EDIT: I'd suggest to add the "Admin" text in a span
tag to help select the element and then use .prev()
to select the checkbox
$("span:contains('Admin')").prev().prop('checked', true);
Updated the Fiddle for this case.
$("span:contains('Super User')").prev().prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="hidden" name="value[1].value" value="416800-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
<span>Admin</span>
<input type="hidden" name="value[1].value" value="416900-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
<span>User</span>
<input type="hidden" name="value[1].value" value="417000-000" class="__web-inspector-hide-shortcut__" checked="checked">
<input type="checkbox" name="value[1].enabled" value="on">
<span>Super User</span>
Upvotes: 2