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

187
Visualizações
How to change font size by javascript from css

I have some css.

.A B{
  font-size:34%
}

How can I change font-size from 34% to 30%? by javascript. I tried some script like this.

document.querySelectorAll('.card-full, .card-text')[0].style.fontSize='30%';

But, font size is changed weird.
And Chrome DevTools show Elements information like this.

.A B{
  font-size:34%
}
style attribute {
  ~~font-size:30%;~~
}

Oh... stackoverflow can't support strikethrough.

How can I change font size from css by javascript?

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

0

It is strikethrough most likely because there're other css that has higher specificity.

The way you change the font-size using JS is correct. It would be helpful if you provide more details.

Edit: the arg inside querySelectorAll is probably not what u want as mentioned by @mplungjan.

document.querySelectorAll('.card-full, .card-text')[0].style.fontSize='30%';

The above will change the card-full element's font-size instead of the first card-text

about 4 years ago · Juan Pablo Isaza Relatório

0

It is very unclear what you want. Your spaces and commas and missing dots make it tricky to guess

Here is an example of what I think you meant - the 90% is for illustration

document.querySelector('.card-full .card-text').style.fontSize='90%';
.A .B{
  font-size:34%
}
<div class="A card-full card-text">First card<p class="B card-text">Some text</p></div>
<div class="A card-full card-text">Second card<p class="B card-text">Some text</p></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

document.getElementsByClassName('B')[0].style.fontSize = "30%";

if you need to '!imporant' option

document.getElementsByClassName('B')[0].setAttribute('style', 'font-size: 30% !important');
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