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

138
Visualizações
Are DOM elements treated as objects?

Hello I am new to javascript and I came across this code which I don't quite get and the code is

let element = document.querySelector(".some-class")
element.x = "hello world"
console.log(element.x)

And this code logs hello world to the console. So my question is that are the DOM elements treated as objects(because in objects we use the same syntax like obj.color for example.) And what does that x mean in general?

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

0

With element.x you added a attribute to your element object, with just this code, document.querySelector(".some-class") is useless, it would do the same if you just had declared an empty variable element.

However, you can edit the element in the HTML with this syntax, for example

let element = document.querySelector(".some-class");
element.innerHTML = "bb";
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