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

164
Visualizações
jquery checkbox alert text (but not value attr )

the example is working fine, but is that possible to make it alert $200,000 instead of 'value' ?

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 Respostas
Responde à pergunta

0

Change the line: return this.value; to return the innerText of parent element (instead of input's value).

Snippet:

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 Relatório

0

Using vanilla 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 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