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

224
Visualizações
How to get inner html text of sibling element

Why doesn't this print out the text of the span, "Apple "?

<label class="search-recipe-chkbox fruitLabel">
  <input type="checkbox" class="checkbox check-box-mob-filters check-box-desktop" id="12DSKT" name="Apple" value="12">
  <span class="checkmark"></span>
  <span class="ingredient-label">Apple <span class="recipe-count" id="12numDSKT">(1)</span></span>
</label>
for (var checkbox of checkboxes) {
  if (checkbox.checked == true) {
    console.log($(checkbox.id).siblings('.ingredient-label').text());
  }
}

checkboxes is just all the checkboxes (input) in the form and given that Apple is checked.

Thank you

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

0

Check the checkbox.id - in the console.log

It needs to have a # in the front:

for (var checkbox of checkboxes) {
  if (checkbox.checked == true) {
    console.log($('#'+checkbox.id).siblings('.ingredient-label').text()); // like this
  }
}

Edit

Here's a better solution as told by Teemu. Only checkbox also works:

for (var checkbox of checkboxes) {
  if (checkbox.checked == true) {
    console.log($(checkbox).siblings('.ingredient-label').text()); // like this
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

There are multiple reasons that this could occur, however here is my solution to your problem.

for (var checkbox of checkboxes) {
  if (checkbox.checked) {
    var val = checkbox.parentElement.querySelector('.ingredient-label').textContent;
    console.log(val);       
  }
}   
about 4 years ago · Juan Pablo Isaza Relatório

0

You can also use - console.log($("[id]").siblings('.ingredient-label').text());

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