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

279
Visualizações
Why color, size and weight is not changing by ranger

Why this is not working. The size, weight, color not changing. I created a label and some range input to change its size, weight and color.

Html

<label class="main" id="word">Sample input</label>
            
        
            <label for="text">Text: </label>
            <input type="text" name="text" id="data" placeholder="Type your word"><br>
<label for="s">Size: </label>
            <input type="range" name="s" id="size" from="10" to="50"><br>
            <label class="we"for="w">Weight: </label>
            <input type="range" name="w" id="weight"><br>
            <label for="c">Color: </label>
            <input type="color" name="c" id="color">

JavaScript


var text = document.getElementById('word');

var data = document.getElementById('data').value;

var size = document.getElementById('size').value;

var weight = document.getElementById('weight').value;

var color = document.getElementById('color').value;

text.style.color = color;
text.style.fontWeight = weight;
text.style.fontSize = size;

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

0

I have make some steps to make your code works:

Step 1: Bring all of your code into a changeStyle() function and put it into onchange="changeStyle()" in all of <input> tag. And I run changeStyle() on init page also to make it set your sample data by current data from HTML.

Step 2: Fix .style.fontSize range by set the value to size + 'px'.

Step 3: Fix HTML attributes from="10" to="50" to min="10" max="50". You can find out more here.

function changeStyle() {
  var text = document.getElementById('word');

  var data = document.getElementById('data').value;

  var size = document.getElementById('size').value;

  var weight = document.getElementById('weight').value;

  var color = document.getElementById('color').value;

  text.innerHTML = data;
  text.style.color = color;
  text.style.fontWeight = weight;
  text.style.fontSize = size + 'px';

}

changeStyle();
<label for="text">Text: </label>
<input type="text" name="text" id="data" placeholder="Type your word" onchange="changeStyle()" value="Sample input"><br>
<label for="s">Size: </label>
<input type="range" name="s" id="size" min="10" max="50" onchange="changeStyle()"><br>
<label class="we" for="w">Weight: </label>
<input type="range" name="w" id="weight" min="10" max="600" onchange="changeStyle()"><br>
<label for="c">Color: </label>
<input type="color" name="c" id="color" onchange="changeStyle()">


<br/><label class="main" id="word" onchange="changeStyle()">Sample input</label>

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