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

191
Visualizações
Do browsers assure that if an inline css property has not been set, the value of "element.style.property" will always be a empty string?

For example:

<xxx id="myid" ...></xxx>

If no code or nobody sets the inline css properties of element "xxx", then document.getElementById("myid").style.property always equals ""?

Do w3c standards or all browsers assure it?

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

0

On Blink based browsers, it seems to always set it to an empty string.

MDN recommends clearing them by setting them to null, which then isn't an empty string, but upon testing this in a blink based browser, it seems to reset to an empty string. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

On some browsers, when a CSS property hasn't been set, it is literally undefined, which is quite different from null or "" (an empty string).

You can force some consistency between all browsers and updated values by coercing to an empty string.

document.getElementById("myid").style.property || ""

Edit - New properties

CSS is rapidly changing, with new properties appearing frequently. As such, it got me thinking, what happens in blink based browsers with unrecognised properties.

The answer is not consistent with known properties, and instead, they are undefined if not set. Equally these can be set to null.

I would recommend using falsy checks when appropriate to solve this problem.

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