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

284
Visualizações
I cannot change the display on a class in javascript

I'm trying to change visibility of an element in JavaScript.

I tried running openloginHud(); with the console window and it responded with undefined

I have also tried using console and that told me the error was

Uncaught TypeError: Cannot read properties of null (reading 'style') at openloginHud (index.js:20:40) at HTMLInputElement.onclick (index.html:13:110)

My code

HTML:

<div class="login"><input id="login" type="submit" name="login" onclick="openloginHud();" value="Login"/></div>
<div class="loginHud">
        <div class="inputs">
            <h1>Login</h1>
            <div class="email"><input type="email" name="email" id="email" placeholder="Email"></div>
            <div class="password"><input type="password" name="password" id="pass" placeholder="Password"></div>
            <div class="submit"><input id="submit" type="submit" name="Login" onclick="login();" value="Login"/></div>
        </div>
    </div>

JavaScript:

function openloginHud() {
    document.getElementById("loginHud").style.display = "block";
}

Css:

.inputs {
    background-color: rgb(94, 94, 94);
    position: absolute;
    display: none;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    padding: 0 100px;
    padding-top: 50px;
    padding-bottom: 100px;
    border-radius: 55px;
}

.inputs .email {
    padding-bottom: 15px;
}

.inputs .email input,
.inputs .password input {
    padding: 10px;
    background: none;
    outline: none;
    border: 5px solid white;
    border-radius: 15px;
    color: white;
}

.inputs .email input::placeholder,
.inputs .password input::placeholder {
    color: rgb(199, 199, 199);
}

.inputs h1 {
    color: white;
    font-size: 65px;
    text-align: center;
}

.inputs .password input,
.inputs .email input {
    height: 20px;
    width: 250px;
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

loginHud is a class, not an ID. You have 2 options:

If there is only one element with that class, just change it to an ID:

<div id="loginHud">

If there are more than one elements, use getElementsByClassName and loop through it:

for (let el of document.getElementsByClassName('loginHud')) {
    el.style.display = 'block';
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Change "document.getElementbyID" to

function openloginHud() {
    document.querySelector(".loginHud").style.display = "block";
}

querySelector allows you to use css Selectors like "#" and ".". It makes it easier to switch between the two types seamlessly. Just remember to use the CSS Selector, and it will change the style.

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