javascript - Switching temperatures using a Bootstrap toggle -
i using api provides temperatures in both celsius , fahrenheit , trying switch between 2 using toggle so:
//toggle temperature var celc = $("#convert-temp").prop('checked'); var temp_c = 20; // dummy data var temp_f = 60; // dummy data if (celc == false) { $("#temp_c").html(temp_c + "<span>℃</span>"); } else if (celc == true) { $("#temp_c").html(temp_f + "<span>℉</span>"); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="checkbox"> <label><input type="checkbox" id="convert-temp" data-toggle="toggle" data-on="℃" data-off="℉">toggle temperature</label> </div> <div id="temp_c"></div>
this toggle doesn't switch between 2 temperatures. variables temp_c , temp_f being fetched api.
i've added change code
<div class="checkbox"> <label><input type="checkbox" id="convert-temp" data-toggle="toggle" data-on="℃" data-off="℉">toggle temperature</label> </div> <h1 id='temp_c'></h1> $(document).ready(function(){ $('#convert-temp').click(function(){ var temp_c = 51; loaded api var temp_f = 125 var celc = $("#convert-temp").prop('checked'); if(celc === false){ $("#temp_c").html(temp_c+"<span>℃</span>"); }else if(celc == true) { $("#temp_c").html(temp_f+"<span>℉</span>"); } }) })
Comments
Post a Comment