Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Cómo obtener el texto html interno del elemento hermano

¿Por qué esto no imprime el texto del lapso, "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 de verificación son solo todas las casillas de verificación (entrada) en el formulario y dado que Apple está marcado.

Gracias

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Verifique checkbox.id - en console.log

Necesita tener un # en el frente:

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

Editar

Aquí hay una mejor solución según lo dicho por Teemu. Solo checkbox de verificación también funciona:

 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 Report

0

Hay varias razones por las que esto podría ocurrir, sin embargo, aquí está mi solución a su problema.

 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 Report

0

También puede usar - console.log($("[id]").siblings('.ingredient-label').text());

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!