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

195
Visualizações
Using checkbox to show/hide dynamic divs doesn't work

I have a webpage that uses javascript and ajaxpage to load a page inside another page without having to refresh. The code looks like this:

<a href="javascript:ajaxpage('r/gd.php','releases');">LINK</a>

Clicking on LINK will load 'r/gd.php' into the DIV I have labeled as 'releases'. I got the backbone of the code to accomplish this from this website here:

http://dynamicdrive.com/dynamicindex17/ajaxcontent.htm

This all works great until I attempt to use checkboxes to filter the content of a DIV on a loaded page. What I would like to do is have a series of checkboxes with unique IDs like this:

<input type="checkbox" id="all"> Show All
<input type="checkbox" id="red"> Red
<input type="checkbox" id="orange"> Orange
<input type="checkbox" id="yellow"> Yellow

These would then show/hide various DIVs when checked/unchecked that contain a series of classes like so:

<div id="box" class="all red"><?php echo $gdclock; ?></div>
<div id="box" class="all red orange"><?php echo $gdheart; ?></div>
<div id="box" class="all orange"><?php echo $gdblue; ?></div>
<div id="box" class="all red orange yellow"><?php echo $gdwhite; ?></div>
<div id="box" class="all yellow"><?php echo $gdclearsplat; ?></div>
<div id="box" class="all red yellow"><?php echo $gdredblack; ?></div>

I'm not sure how to accomplish this on a page that is loaded the way I am doing so. I have used examples such as this and this that work great when just visiting a URL, but as soon as I go to use the same code on a dynamically loaded page, it does nothing.

Is there something I am missing here? This is a link to my webpage (best viewed on desktop). If you click on ALL ALBUMS in the left side bar, a page full of vinyl records will load with checkboxes at the top. I'd like to filter based on colour (using classes/IDs as described above) and hide everything else. Have more than one checkbox active at a time is ideal.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your original question does not seem to show a link between the Ajax call and selectively turning on/off Html elements. Is this what you are seeking?

$(document).ready(() => {
  $("#all div").hide();
  $("p#checkboxes > :checkbox").change(() => {
    $("#all div").hide();
    if ($("#all").is(":checked")) $("#all div").show();
    else {
      if ($("#red").is(":checked")) $(".red").show();
      if ($("#orange").is(":checked")) $(".orange").show();
      if ($("#yellow").is(":checked")) $(".yellow").show();
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<p id="checkboxes">
  <input type="checkbox" id="all"> Show All
  <input type="checkbox" id="red"> Red
  <input type="checkbox" id="orange"> Orange
  <input type="checkbox" id="yellow"> Yellow
</p>

<div id="all">
  <div class="red">Only red stuff</div>
  <div class="red orange">red & orange stuff</div>
  <div class="orange">Only orange stuff</div>
  <div class="red orange yellow">anything</div>
  <div class="yellow">Only yellow things</div>
  <div class="red yellow">Red & yellow</div>
</div>

If above is not what you need, please provide more details in your question.

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