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

168
Views
texto de alerta de casilla de verificación de jquery (pero no attr de valor)

el ejemplo funciona bien, pero ¿es posible alertar $ 200,000 en lugar de 'valor'?

 var checkboxes = $('input[name="price[]"]'); checkboxes.on("click", function() { var $checked = checkboxes.filter(":checked"), checkedValues = $checked.map(function() { return this.value; }).get(); alert(checkedValues); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul id="searchFilter"> <li><input type="checkbox" name="price[]" class="cb_price" value="1"> $200,000 to $299,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="3"> $300,000 to $399,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="5"> $400,000 to $499,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="8"> $500,000+</li> </ul>

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

0

Cambia la línea: return this.value; para devolver el innerText del elemento principal (en lugar del valor de entrada).

Retazo:

 var checkboxes = $('input[name="price[]"]'); checkboxes.on("click", function() { var $checked = checkboxes.filter(":checked"), checkedValues = $checked.map(function() { return this.parentElement.innerText; }).get(); alert(checkedValues); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul id="searchFilter"> <li><input type="checkbox" name="price[]" class="cb_price" value="1"> $200,000 to $299,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="3"> $300,000 to $399,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="5"> $400,000 to $499,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="8"> $500,000+</li> </ul>

about 4 years ago · Juan Pablo Isaza Report

0

Usando vainilla JS:

 const checkboxes = [...document.querySelectorAll('input[name="price[]"]')]; for (const checkbox of checkboxes) { checkbox.addEventListener('change', function(event) { const checkedValues = checkboxes.filter(cb=>cb.checked).map(cb=>cb.parentElement.textContent); console.log(checkedValues); }); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul id="searchFilter"> <li><input type="checkbox" name="price[]" class="cb_price" value="1"> $200,000 to $299,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="3"> $300,000 to $399,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="5"> $400,000 to $499,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="8"> $500,000+</li> </ul>

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!