Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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) {

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

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


    })

}

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading