gitbrent / bootstrap4-toggle

Bootstrap 4 Switch Button / Toggle
https://gitbrent.github.io/bootstrap4-toggle/
MIT License
213 stars 67 forks source link

help to make 2 divs with bootstrap4-toggle #48

Open jesussuarz opened 4 years ago

jesussuarz commented 4 years ago

I'm pretty new to javascript. so I need a little help with this.

I try to use this:

<input id="toggle-event" type="checkbox" data-toggle="toggle">
<div id="console-event"></div>
<script>
  $(function() {
    $('#toggle-event').change(function() {
      $('#console-event').html('Toggle: ' + $(this).prop('checked'))
    })
  })
</script>

I will make a section of plans on my website, yearly and monthly.

You can see the example on this website: https://cangurohosting.com/hosting/

I need to start 1 div with a content and then when they click on the toggle then hide the first one and start the second one.

I hope you can understand me.

Kholodny commented 4 years ago

Hi! It's very easy! I hope you understand.

$("#toggle-event").change(function() {
    if ($('#toggle-event').is(":checked")){
        $('.divforhide').hide(); //multi hide all divs
        $('.divfordisplay').css('display', 'inline'); //multi show all divs
        //or: 
        $("#first,#second,#third,#etc").hide() //multi hide all id's
        $("#first,#second,#third,#etc").css('display', 'inline') //multi hide all id's
    } else {
        $('.divforhide').hide(); //multi hide all divs
        $('.divfordisplay').css('display', 'inline'); //multi show all divs
        //or: 
        $("#first,#second,#third,#etc").hide() //multi hide all id's
        $("#first,#second,#third,#etc").css('display', 'inline') //multi show all id's
    } 
});

Don't forget to import jquery