Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda