0

I'm trying to toggle between 2 divs and I can't even get through the first challenge... to catch the radiobutton click event with jQuery selector.

$("input[name='radio_btn_options']").on("click", function(){
    debugger;
    alert("1234");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="btn-group btn-group-toggle" style="margin:15px" data-toggle="buttons">
    <label class="btn btn-secondary active">
        <input type="radio" name="radio_btn_options" id="diagramRB" autocomplete="off" checked> Diagram
    </label>
    <label class="btn btn-secondary">
        <input type="radio" name="radio_btn_options" id="listRB" autocomplete="off"> List View
    </label>
</div>

I don't get no error message no nothing. Nothing just happens have i done something wrong??

0stone0
  • 34,288
  • 4
  • 39
  • 64
Rob
  • 147
  • 2
  • 11
  • I've converted your plain code into a stack-snippet. The snippets seems to work just fine! – 0stone0 Dec 28 '20 at 15:43
  • My guess, you try to access the element before it is rendered on the page. `console.log($("input[name='radio_btn_options']").length)` – epascarello Dec 28 '20 at 15:44
  • Seems its working fine, just checked your snippet?? On radio click i can see the alerts. – amit wadhwani Dec 28 '20 at 15:50
  • 1
    Most likely a dupe of https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element – epascarello Dec 28 '20 at 15:54
  • okey it worked when i changed to 'change' event instead of click event – Rob Dec 28 '20 at 16:03

0 Answers0