How to add values ​from the dom selector?

Viewed 57

I use html () to get the value of the html attribute then I add 2 values ​​but it's just like adding a string, how can I add the Dom selector to add numbers?

var phantram = $('#giamtheophantram').html();
var phantram1 = $('#chuadungma').html();
if(phantram1 == 'contuer'){
  phantram1 = 0;
}
$(document).ready(function() {
document.getElementById('tonggiam').innerHTML = phantram + phantram1;
});
1 Answers

+ append strings (there is no auto retype as in PHP), use parseInt() to retype to numbers and make a sum. If decimals are allowed, use parseFloat().

$(document).ready(function() {
    document.getElementById('tonggiam').innerHTML = parseInt(phantram) + parseInt(phantram1);
});
Related