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

236
Visualizações
how do I drive the width of span class with variable

Please where am I mistaking? I am trying to change the progress bar base on variable and it is not working.

    <script>
        function grafWidth(GtempPar) {
         var GtempPar = 30;
          
        document.getElementById('progress-in').style.width = GtempPar + "px";
        }
    </script>

    <div class="progress">
        <a class="majko">Temp_G_back</a>
        <span class="progress-val"><div id="Gtemp"></div>°C</span>
        <span class="progress-bar"><span class="progress-in".style.width =" 80px"></span></span>
    </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The most likely reason is that the span is an inline element and as such you can't specify a width (or margins / padding / height etc). In order to apply the styling try - making the span display y: inline-block and you should be able to apply width changes as expected.

Also the span has an id not a class and you have to call the function with an argument that you are wanting the pass into the function. and the var inside the function is redundant.

function grafWidth(GtempPar) {
   document.getElementById('progress-in').style.width = GtempPar + "px";
}
        
        
grafWidth(150); // this calls the function and passes 150 in to set the width of the progress bar to 150px (out of 200)
span {
  display: inline-block;
}

.progress-bar  {
  border: solid 1px blue;
  width: 200px;
  height: 32px
}

#progress-in {
  background: red;
  position: relative; 
  z-index: 1;
  width: 100px;
  height: 32px;
}
<div class="progress">
    <a class="majko">Temp_G_back</a>
    <span class="progress-val"><div id="Gtemp"></div>°C</span>
    <span class="progress-bar"><span id="progress-in"></span></span>
</div>

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