JavaScript for jQuery

1

I have a question about jQuery , how would the following code Pure JavaScript be using jQuery ?

function writeTotal(value){
    var total = document.getElementById('total');
    total.innerHTML = floatToMoneyText(value);
}
    
asked by anonymous 20.09.2018 / 19:02

2 answers

2

A reduced form:

function writeTotal(value) {
    $('#total').html(floatToMoneyText(value));
}

This floatToMoneyText could probably also be converted to jQuery, but would have to know what you do exactly in it

    
20.09.2018 / 19:07
1

And how about testing the value parameter to see if it is null / empty:

function writeTotal(value) {

var innerHtml = "";

if (value === window.undefined || value === null || value === "") {
    innerHtml = "R$ 0,00";
}
else {
    innerHtml = floatToMoneyText(value);
}

$('#total').html(innerHtml);
};
    
20.09.2018 / 19:51