Reputation: 6555
I have a bunch of checkboxes I only want divActions
to be viable .show() when 1 or more of these checkboxes are ticked. I then want to hide divActions
if none or all are deselected.
How can this be done?
This is my start.
jquery
$(document).ready(function() {
var $divActions = $('#actions');
var $clickActions = $('.contacts');
$divActions.hide()
$clickActions.click(function(){
$divActions.show()
});
html
{% for item in contacts %}
<tr>
<td><input type="checkbox" name="contacts" value="{{ item.id }}" class="contacts"/></td>
<td>{{ item.full_name|capfirst }}</td>
<td>{{ item.mobile }}</td>
<td class="td-actions">
<a class="btn btn-small" href="{{ item.get_delete_url }}">
<i class="icon-trash"></i>
</a>
</td>
</tr>
{% endfor %}
Upvotes: 0
Views: 46
Reputation: 17927
have a look here: http://jsfiddle.net/CFazb/
code
$("input:checkbox").change(function () {
if ($("input:checkbox:checked").length > 0)
$("#actions").show();
else
$("#actions").hide();
})
change the code accordingly to your needs
Upvotes: 1
Reputation: 74420
Try using change handler:
$clickActions.on('change',function(){
if($clickActions.is(':checked'))
$divActions.show();
else $divActions.hide();
});
Upvotes: 2
Reputation: 318232
$('.contacts').on('change', function() {
$('#actions').toggle( $('.contacts').is(':checked') );
});
Upvotes: 3
Reputation: 3886
onchange
-event handler to the each checkbox to run function from 1.Upvotes: 1