How to remove padding from html element when pasted in js


there is a problem with inserting html into js , when inserting indents are added and I don’t understand why. Building a simple calculator

for (var i = 0; i < num.length; i++) {
    num[i].addEventListener("click", function () {
        if (!operator) {

            num1 += this.textContent
            result.innerHTML = num1;
        } else if (operator.length > 0) {

            num2 += this.textContent
            result.innerHTML = num2;



>Solution :

When using element.textContent you are getting the exact content from the source HTML, including whitespace in case the HTML isn’t minified.

As an alternative, you can use element.innerText which gives the rendered text and does not normally include extra whitespace.

Leave a Reply Cancel reply