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

119
Views
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 answers
Answer question

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 Report

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 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!