Recommand · October 14, 2021 0

How do I add a $ sign before the number using css in a javascript function?

Closed. This question needs details or clarity. It is not currently accepting answers.


Want to improve this question? Add details and clarify the problem by editing this post.

Closed 1 hour ago.

Improve this question

I want to add a dollar sign before the number. I was able to add font color to the text but not dollar sign. Kindly help.

code:

for(x in cars){
    let carsElem = document.createElement('TD');
    if(model.includes(year)){
        carsElem.style.color = 'red';
        
    }

A better job is adding a dollar sign to text but if you want to use CSS, you should add a specific class (for example dollared) and add it to your element. then adding the below code to your CSS file:

.dollared::before {
    content: '$';
}

The only way to add text before an element with CSS is by using a ::before pseudo-element in the style sheet.

So add the following to your CSS:

.dollar::before {
    content: "$";
}

Then add the dollar class to your element.

for(x in cars){
    let carsElem = document.createElement('TD');
    if(model.includes(year)){
        carsElem.style.color = 'red';
        carsElem.classList.add("dollar");
    }
}