Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How do I dynamically add CSS classes to HTML elements if value is less or greater than 0?

How can I dynamically add css classes to the <div class="coin__row-text"> elements based on whether or not the value of the element is greater than 0?

HTML:

<template> 
    <div class="coin-block-wrapper">
        <div class="coin__wrapper">
            <div v-for="(value, key) in coins" :key="value" class="coin__row">
                <div class="coin__row-div">
                    <img src="{{ }}" class="coin__row-logo">
                    <div class="coin-name">{{key}}</div>
                    <div class="coin-name">USDT</div>
                </div>
                <div class="coin__row-div-large">
                    <div id="coin__row-small-div">
                        <div class="coin__row-text">{{value.USD.PRICE}}</div>
                        <div class="coin__row-text">{{value.BTC.PRICE}}</div>
                    </div>
                    <div id="coin__row-small-div">
                        <div class="coin__row-text">{{value.USD.CHANGEPCTHOUR}}%</div>
                        <div class="coin__row-text">{{value.BTC.CHANGEPCTHOUR}}%</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

Styles:

<style scoped>
    .positive {
        color: green;
    }
        
    .negative {
        color: red;
    }
</style>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should try binding class. Something like that:

<div :class="getDivClasses(value.USD.PRICE)">

and inside methods:

getDivClasses(value) {
  return value > 0 ? "positive" : "negative";
},
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!