0

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?

2 Answers 2

1

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".

Sign up to request clarification or add additional context in comments.

Comments

0
var checkbox = $('checkbox').attr("checked");

if (checkbox == 'checked') {
    $('#divID').show(); // #divID is the ID for the hidden DIV which you want to show.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.