Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created November 14, 2016 16:24
Show Gist options
  • Save alexandreaquiles/b0792460ac99d48946b7e584b7b1960c to your computer and use it in GitHub Desktop.
Save alexandreaquiles/b0792460ac99d48946b7e584b7b1960c to your computer and use it in GitHub Desktop.
Cálculo IMC com jQuery
<!DOCTYPE html>
<html>
<body>
<label>Peso <input id="peso"/> kg</label><br/>
<label>Altura <input id="altura"/> m</label><br/>
<button id="botao">Calcular IMC</button>
<div id="resultado">
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$('#botao').click(function () {
var peso = $('#peso').val();
var altura = $('#altura').val();
var imc = peso / (altura * altura);
var hr = $('<hr>');
var spanIMC = $('<span>').text('IMC: ' + imc);
$('#resultado').append(hr).append(spanIMC);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment