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
Create CSS using js?

So In javascript you can do things like

document.querySelector('html').style.filter = 'invert(100%)'

Which Inverts colors on the entire webpage but is there anyway to use

document.querySelector('html').style.pointer = 'something'

or a way to add a css rule or something to the document?

example you have an element like this

hello

then js gives an class hello

then js adds a css rule?

.why {}

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

0

You can add a css class to specific element with (and then create the styles from the css file):

[NameOfTheElement].classList.add("mystyle")

This will work for the document:

document.querySelector('html').classList.add('new-class');

This will work for the body:

document.querySelector('body').classList.add('new-body-class')
about 4 years ago · Juan Pablo Isaza Relatório

0

You could write to the document using document.write

document.write(`
<style>
  #text {
    color: red;
  }
</style>`)
<h1 id='text'>Hello</h1>

Or, you can also create an element and append it to the document

let style = document.createElement('style')
style.innerHTML = `
.text {
  color: red;
}
`

document.body.appendChild(style)
<h1 class='text'>Hello</h1>

about 4 years ago · Juan Pablo Isaza Relatório

0

There are a few ways.

  1. If you already have styles defined for a certain class within your stylesheet, you can do what Erasmo said above:
element.classList.add('className');
  1. You can also use:
element.style.color = 'white';
  1. Or add a style attribute to the element:
element.setAttribute('style', 'color: white; background-color: green;');
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