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

195
Visualizações
change In document style.. without replacing it

I found this on the web

function largeFont() {
  const dStyle = document.querySelector('style');
  dStyle.innerHTML = 'p {font-size: 2rem;}';
}

But this takes everything inside of <style></style> wipes it clean and puts in "p {font-size: 2rem;}". Is it possible to change specific thing inside of <style></style> like

document.querySelector('style').body
or 
document.querySelector('style').#box
document.querySelector('style').box.background-color

Or whatever. I know how to do inline, But I would rather not in this case. I mean, I guess I could just parse the whole thing and find replace that text...

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

0

If the style is inline on the page, you can insert content into it with +=, which will keep the existing content.

const dStyle = document.querySelector('style');
dStyle.innerHTML += 'p {font-size: 2rem;}';
//              ^^^

If the style is not inline on the page, or you don't want to use the above approach, you can also use insertRule.

const sheet = document.querySelector('style').sheet;
sheet.insertRule(`
p {
  font-size: 2rem;
}
`,
sheet.cssRules.length
);
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