I’ve got two inputs in a div that I want to divide one by the other.
<div>
<input type="number" id="a"> / <input type="number" id="b">
<input type="submit">
<p class="result">RESULT HERE</p>
</div>
How can the maths of this be done with jquery?
It really depends when you want the calculation to take place, but the maths itself is incredibly simple. Just use the standard division operator,
/:I guess it also depends if you only want to support integer division (that’s why I’ve used
parseInt– you could useparseFloatif necessary).Also, as mentioned in the comments on your question,
labelis not a valid attribute. A better option would be to useid, or if you need to use an arbitrarily named attribute, use HTML5data-*attributes.Update based on comments
As you have stated that you want the code to run when a button is clicked, all you need to do is bind to the
clickevent: