javascript - Switch box:multiple switch boxes are not working in my page -


i have 1 switch button works fine. when go more number of switch buttons, functionality not working. if click on second one, first switch gets moved on off or off on

here css , html:

<html> <head> <style type="text/css">    .onoffswitch {        position: relative; width: 90px;        -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;    }    .onoffswitch-checkbox {        display: none;    }    .onoffswitch-label {        display: block; overflow: hidden; cursor: pointer;        border: 2px solid #e6e6e6; border-radius: 50px;    }    .onoffswitch-inner {        display: block; width: 200%; margin-left: -100%;        transition: margin 0.3s ease-in 0s;    }    .onoffswitch-inner:before, .onoffswitch-inner:after {        display: block; float: left; width: 50%; height: 36px; padding: 0; line-height: 36px;        font-size: 16px; color: white; font-family: trebuchet, arial, sans-serif; font-weight: bold;        box-sizing: border-box;    }    .onoffswitch-inner:before {        content: "yes";        padding-left: 13px;        background-color: #61a1e1; color: #ffffff;    }    .onoffswitch-inner:after {        content: "no";        padding-right: 13px;        background-color: #f01f1f; color: #ffffff;        text-align: right;    }    .onoffswitch-switch {        display: block; width: 27px; margin: 4.5px;        background: #ffffff;        position: absolute; top: 0; bottom: 0;        right: 50px;        border: 2px solid #e6e6e6; border-radius: 50px;        transition: 0.3s ease-in 0s;     }    .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {        margin-left: 0;    }    .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {        right: 0px;     } </style> </head> <body>    <div class="onoffswitch">        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>        <label class="onoffswitch-label" for="myonoffswitch">            <span class="onoffswitch-inner"></span>            <span class="onoffswitch-switch"></span>        </label>    </div>    <div class="onoffswitch">        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>        <label class="onoffswitch-label" for="myonoffswitch">            <span class="onoffswitch-inner"></span>            <span class="onoffswitch-switch"></span>        </label>    </div>  </body> </html> 

now want worked switch buttons separately. not getting going wrong.

please me out this.

many in advance

working jsfiddle demo

in demo fiddle when click on second switch button first 1 moving.

both elements need have different ids make work. please see updated fiddle https://jsfiddle.net/mileandra/skrn9/30/

<div class="onoffswitch">        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked="checked" />        <label class="onoffswitch-label" for="myonoffswitch">            <span class="onoffswitch-inner"></span>            <span class="onoffswitch-switch"></span>        </label>    </div>    <div class="onoffswitch">        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch2" checked="checked" />        <label class="onoffswitch-label" for="myonoffswitch2">            <span class="onoffswitch-inner"></span>            <span class="onoffswitch-switch"></span>        </label>    </div> 

Comments