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

152
Visualizações
How do I get the value of checkbox?

HTML :

<input type="checkbox" aria-checked="false" class="cloud-private" value="" data-spm-anchor-id="a800.io">

My java script : ( i want to click this checkbox if it is not checked ,but this does not work )

var z = document.getElementsByClassName('cloud-private'); 
if (z[0].aria-checked=='false'){ 
    z[0].click(); 
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Should not be using aria-checked here in this way. Should be using the checked attribute as is shown in the checkbox spec on MDN.

let cloudPrivateCbxs = document.querySelectorAll('.cloud-private');

if (cloudPrivateCbxs && !cloudPrivateCbxs[0].checked) { 
    cloudPrivateCbxs[0].click();
}

Here I used a useful variable names (never use single letter variable names except for simple counters like those in for loops), used querySelectorAll instead of getElementsByClassName, then I first check if the variable contains anything, then I simply check the checked attribute to see if it returns false. It is returning a boolean so I can use the logical NOT operator ! rather than check directly if it is equal to false.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use querySelector to find the element with that class, and that aria-checked attribute. Then click it. Just make sure you spell things correctly (aria, not area, for example).

const selector = '.cloud-private[aria-checked="false"]';
const z = document.querySelector(selector);

// If the element exists, check it
z && z.click();
<input type="checkbox" aria-checked="false" class="cloud-private">

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