Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
How can I manipulate HTML DOM with data from Database and Node (Mongoose)

Following the tutorial https://www.youtube.com/watch?v=u3rylF3y3og&ab_channel=TraversyMedia

I'm coding something that has a Star review feature. I want to change the width (through document.querySelector('').style.width = starPercentage) of elements to determine how many stars a review gave:

function getRatings() {
      for (let rating in ratings) {
        // Get percentage
        const starPercentage = (ratings[rating] / starsTotal) * 100;

        // Round to nearest 10
        const starPercentageRounded = `${Math.round(starPercentage / 10) * 10}%`;

        // Set width of stars-inner to percentage
        document.querySelector(`.${rating} .stars-inner`).style.width = starPercentageRounded;

        // Add number rating
        document.querySelector(`.${rating} .number-rating`).innerHTML = ratings[rating];
     }
}

But instead of the hard-coded values I'm getting the data from mongoose and express. What's the best way to manipulate the stars of each review?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The following article contains simple technique for filling star ratings in Javascript. https://webdesign.tutsplus.com/tutorials/a-simple-javascript-technique-for-filling-star-ratings--cms-29450

about 4 years ago · Juan Pablo Isaza Relatório

0

CSS

and add the correct css to the html class tag for example ( , ....)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda