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>&#8451;</span>");  } else if (celc == true) {    $("#temp_c").html(temp_f + "<span>&#8457;</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="&#8451;" data-off="&#8457;">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="&#8451;" data-off="&#8457;">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>&#8451;</span>");                     }else if(celc == true) {                         $("#temp_c").html(temp_f+"<span>&#8457;</span>");                     }       })     }) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -