JSFiddle - React, Tailwind, and code Playground
by alnitak
HTML
<input name="add" class="add" type="text"> <br/>
<input name="add" class="add" type="text"> <br/>
<input name="add" class="add" type="text"> <br/>
<input name="add" class="add" type="text"> <br/>
<input id="add" type="button" value="add" />
JavaScript
function add() {
var sum = 0;
$(".add").each(function() {
sum += +this.value;
});
return sum; // an add function shouldn't really "alert"
}
$('#add').click(function() {
alert(add());
});