-1
<div class="Dropdown js-toggle-only open">
            <div>
              <span>
                  Cat (once select radio, value will be appended)
                </span>
            </div>
            <div class="DropdownMenu js-toggle-only open">
                <label>
                  All
                </label>
                <input type="radio" name="section" checked>

                <label>
                  Dog
                </label>
                <input type="radio" name="section" value="Dog">

                <label>
                 Horse
                </label>
                <input type="radio" name="section" value="Horse">
            </div>
          </div>

JQuery

var radios = $("input[name='section']");
if (radios.is(':checked')){
    var toggle = $('js-toggle-only');
    toggle.removeClass('open');
}

Tried click or if to have 'open' class removed, but open class stayed. When the dropdown flyout opened, it should be closed immediately after selecting one of the radios. Couldn't figure how to force or take open class out once one radio is selected.

1 Answer 1

0

You're missing . in the class selector

var radios = $("input[name='section']");
if (radios.is(':checked')){
  var toggle = $('.js-toggle-only');
//----------------^ here
  toggle.removeClass('open');
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks but with correction, it wouldn't take class out regardless
@joe Can you create an online demo where it doesn't work, which includes the plugin (*if any) and the rest of code..?
thanks again. used settimeout to force it close immediately after click on radio (timeout 50). it may not be good but because of other script delaying with 300.
@joe Other than the typo, your code works fine here. so i'm voting to close the question, if the issue persists, then please update the fiddle or question with the rest of code required to reproduce the issue..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.