Reputation: 10997
I have a form with checkboxes - if one of these is checked, there is some jquery that applies the css class checkboxed
.
I have another div
further down the page that is hidden by default - but if any of the form checkboxes are checked, it should become visible.
I'd like to use something like this
<div class="<%= "hide" unless checkboxed.exists? %>">
but obviously that doesn't work. Is there a way to test if a css class exists on a given page? I know I'll have to use jQuery, but how to then tie this in with the conditional CSS class in the hidden div
?
Upvotes: 0
Views: 846
Reputation: 4735
var checkbox = $('checkbox').attr("checked");
if (checkbox == 'checked') {
$('#divID').show(); // #divID is the ID for the hidden DIV which you want to show.
}
Upvotes: 0
Reputation: 1203
You need to add the div showing logic to the place where you react to checking a box.The addition might look like this:
if($('.checkboxed').length)
$('#hiddenDiv').show();
Your hidden div must have an ID, here I assumed id="hiddenDiv"
.
Upvotes: 1