Bootstrap On-Off Toggle Switch jQuery Plugins

Today, We want to share with you Bootstrap On-Off Toggle Switch jQuery Plugins.In this post we will show you bootstrap toggle switch with text, hear for An ON/OFF switch using bootstrap and jQuery we will give you demo and example for implement.In this post, we will learn about jquery toggle switch programmatcally on off with an example.

Bootstrap On-Off Toggle Switch jQuery Plugins

There are the Following The simple About Bootstrap On-Off Toggle Switch jQuery Plugins Full Information With Example and source code.

As I will cover this Post with live Working example to develop jquery ui toggle switch, so the css toggle switch with text for this example is following below.

Read Also:  Bootstrap Toggle Inside JQuery DataTable

On-Off Toggle Switches Example

index.html

<!DOCTYPE html>
<html>
<head>
    <title>jQuery On-Off Toggle/Switch</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

</head>
<body style="margin:10%;">
<br/>
<hr/>
<h1>jQuery On-Off Toggle/Switch - Example - pakainfo.com</h1>
<div class="switch"> Enable/Disable :<label for="mycheckbox" class="switch-toggle" data-on="On" data-off="Off"></label> <input type="checkbox" id="mycheckbox" /> </div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<style>
  label.switch-toggle { background: url('https://blog.dbrgn.ch/images/2011/11/21/switch.png') repeat-y; display: block !important; height: 12px; padding-left: 26px; cursor: pointer; display: none; } label.switch-toggle.on { background-position: 0 12px; } label.switch-toggle.off { background-position: 0 0; } label.switch-toggle.hidden { display: none; }
</style>
<script>
$(document).ready(function() {
    $('.switch').each(function() {
        var live_switch = $(this).children('input[type=checkbox]');
        var switch_toggle_on_off = $(this).children('label.switch-toggle');
        if (live_switch.length) {
            live_switch.addClass('hidden');
            switch_toggle_on_off.removeClass('hidden');
            if (live_switch[0].checked) {
                switch_toggle_on_off.addClass('on');
                switch_toggle_on_off.removeClass('off');
                switch_toggle_on_off.text(switch_toggle_on_off.attr('data-on'));
            } else {
                switch_toggle_on_off.addClass('off');
                switch_toggle_on_off.removeClass('on');
                switch_toggle_on_off.text(switch_toggle_on_off.attr('data-off'));
            };
        }
    });
    $('.switch-toggle').click(function() {
        var live_switch = $(this).siblings('input[type=checkbox]')[0];
        var switch_toggle_on_off = $(this);  
        if (live_switch.checked) {
            switch_toggle_on_off.addClass('off');
            switch_toggle_on_off.removeClass('on');
            switch_toggle_on_off.text(switch_toggle_on_off.attr('data-off'));
        } else {
            switch_toggle_on_off.addClass('on');
            switch_toggle_on_off.removeClass('off');
            switch_toggle_on_off.text(switch_toggle_on_off.attr('data-on'));
        };
    });
});
</script>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  AJAX Fundamentals Tutorial with Examples

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Bootstrap On-Off Toggle Switch jQuery Plugins.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.