Reputation: 1203
I have a checkbox to add and remove a service. Currently it looks like this:
<div class="cknow" align="center" valign="top">Add/Remove to Checkout
<input type="checkbox" id="ckNow_<?php echo $i;?>" name="ckNow[<?php echo $i;?>]"></input>
</div>
I've also got a script that says this:
$('input[id^=ckNow_]').each(function(){
$(this).bind('click',function(){
if($(this).attr('checked'))
{.... does some stuff }
It's working great as a single checkbox but I'd like to the make the text 'Add/Remove' to be text links (without the input box of the checkbox) so that when Add is clicked it registers as CHECKED and when Remove is clicked, it registers as UNCHECKED.
How can I do this?
Upvotes: 3
Views: 55
Reputation: 47099
You can use:
$('[type=checkbox]').attr('checked', true); // or false
Note: of jQuery 1.7 you should use .prop('checked', ...)
instead:
$('[type=checkbox]').prop('checked', true); // or false
Upvotes: 1
Reputation: 10182
You can use the label
element to assign text to a checkbox, then use CSS to hide the checkbox like so:
HTML
<label>Add/Remove
<input type="checkbox" id="ckNow_" name="ckNow" class="hideme">
</input>
</label>
CSS
.hideme {
display:none;
}
Upvotes: 3