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

140
Visualizações
changing the text content of both h1 and a span that are on the same line

I have a web page acting as input to an imbedded device and I change modes during operation. I have the following h1 line.

 <h1 id="speedlab">Speed: <span id="speedText">0</span>%</h1>

and I update it in one mode using :-

 var output = document.getElementById("speedText");
    vslidertmp = (100 -(Math.abs(vslidertmp-100)/2));
    vslidertmp = (vslidertmp.toFixed(0));
    glslider.value = vslidertmp;
    output.innerHTML = (vslidertmp - 100) ;

when I change modes, I want to update the h1 line to change the header text to "Trim:" and the speedtext content to the value of Trim . I assume updating the speedtext is the same but how do I update the header text from Speed: to Trim: and leave the span element intact. I can't work out the syntax for this.

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

0

I'd put the variable text into its own element, to allow for quick toggling of it when needed.

<h1 id="speedlab">
  <span class="mode">Speed</span>: <span id="speedText">0</span>%
</h1>

And to change it

document.querySelector('.mode').textContent = 'Trim';

While you could replace the contents of the text node as well, without changing the HTML markup...

document.querySelector('#speedlab').childNodes[0].textContent = 'Trim: ';

Giving the mode its own element is nicer.

about 4 years ago · Juan Pablo Isaza Relatório

0

HTML:

header {
   display: flex;
   align - items: center;

   /* Remove the next line if you want the span to appear next to the h1 */
   justify - content: space - between;

   border - bottom: 1 px solid #000;
  padding: 10px 30px;
}
header {
   border - bottom: 1 px solid #000; }
header > h1 { display: inline-block; }
header span { margin-left: 100px; }
<header>
   <h1>Text</h1>
   <span>text2</span>
</header>

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