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

226
Visualizações
How to change CSS style rule within an embedded CSS using JavaScript

So how would I change the CSS styles within embedded CSS with JavaScript only? ex. if this is in the head of the HTML file:

<style>
.middleBTN {
background-color:red;
}
</style>

How would I change it to this within the embedded <style> using JavaScript only?

<style>
.middleBTN {
background-color:blue;
}
</style>

I have an element on a page that does not respond to dynamically changing the color using a JavaScript function. It will however respond to a change from the stylesheet or from the embedded CSS styles.

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

0

The usual way would be to add two styles:

<style>
.middleBTNred
{
 background-color:red;
}
.middleBTNblue
{
 background-color:blue;
}
</style>

then change the class of the button with javascript:

document.getElemenyById('myawesomebutton').className='middleBTNblue';

You are trying to change the style of ALL the red buttons so a more appropriate approach would be:

var myawesomebuttons=document.getElemenyByClassName('middleBTNred');
for(var i=0;i<myawesomebuttons.length;i++)
{
 myawesomebuttons[i].className='middleBTNblue';
}

Or the jquery equivalent.

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