Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
How to get text of label of checked with html tag?

How do I get each text of label of input:checked with <span>? I tried to use "<span>" + $(this).next().find('span').text() + "</span>"; It was not working.

<ul>
 <li class="check_cst">
   <input type="checkbox" id="detail_cate01" name="chk_datail_category" value="">
   <label for="detail_cate01" class="flex_btw items_cnt"><span>cate1</span><b class="flex_cnt items_cnt"></b></label>
 </li>
 <li class="check_cst">
   <input type="checkbox" id="detail_cate02" name="chk_datail_category" value="">
   <label for="detail_cate02" class="flex_btw items_cnt"><span>cate2</span><b class="flex_cnt items_cnt"></b></label>
 </li>
</ul>
var values = "";
$("input[type='checkbox'][name='chk_datail_category']:checked").each(function(){
   values += $(this).next().find('span').text();  //I wanna get this with <span>
});
$("#detail_cate_output").html(values);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You code is basically working except you needed a change event added.

$("input[type='checkbox'][name='chk_datail_category']").change(function() {
  var values = "";
  $("input[type='checkbox'][name='chk_datail_category']:checked").each(function() {
    values += $(this).next().find('span').text(); //I wanna get this with <span>
  });
  $("#detail_cate_output").html(values);
});

Demo

$("input[type='checkbox'][name='chk_datail_category']").change(function() {
  var values = "";
  $("input[type='checkbox'][name='chk_datail_category']:checked").each(function() {
    values += $(this).next().find('span').text(); //I wanna get this with <span>
  });
  $("#detail_cate_output").html(values);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li class="check_cst">
    <input type="checkbox" id="detail_cate01" name="chk_datail_category" value="">
    <label for="detail_cate01" class="flex_btw items_cnt"><span>cate1</span><b class="flex_cnt items_cnt"></b></label>
  </li>
  <li class="check_cst">
    <input type="checkbox" id="detail_cate02" name="chk_datail_category" value="">
    <label for="detail_cate02" class="flex_btw items_cnt"><span>cate2</span><b class="flex_cnt items_cnt"></b></label>
  </li>
</ul>

<div id="detail_cate_output"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You just need onchange Event.

First you need to capture changes check/uncheck of checkbox. and then you can loop through it.

$("input[type='checkbox'][name='chk_datail_category']").change(function() {

 var values = "";

  $("input[type='checkbox'][name='chk_datail_category']:checked").each(function(){
     values += $(this).next().find('span').text();  //I wanna get this with <span>
  });

  $("#detail_cate_output").html(values);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<ul>
 <li class="check_cst">
   <input type="checkbox" id="detail_cate01" name="chk_datail_category" value="">
   <label for="detail_cate01" class="flex_btw items_cnt"><span>cate1</span><b class="flex_cnt items_cnt"></b></label>
 </li>
 <li class="check_cst">
   <input type="checkbox" id="detail_cate02" name="chk_datail_category" value="">
   <label for="detail_cate02" class="flex_btw items_cnt"><span>cate2</span><b class="flex_cnt items_cnt"></b></label>
 </li>
</ul>

<div id="detail_cate_output"></div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda