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

193
Visualizações
Why can't I use a script function to affect variables in html written out by a JSON file?

Hopefully a quick question.

I'm using a JSON file to write out some html and populate with variables from the JSON and append it to part of my html file. This works and is fine. However, I now want to use a different script to apply show and hide filters based on class attributes to the html that has been printed. For some reason, this isn't working. If I just copy and paste the html with variables back into the original document after its been printed out, then the script works though. Is this an issues of synchronicity?

Here's the second script I'm looking to execute if it helps:

$(document).ready(function(){
    var targets = $('.filter'), 
    buttons = $('.filter-button');  

    buttons.click(function(){
        var value = $(this).data('filter');
        if(value == "all")
        {
            buttons.removeClass('checked'); 
            targets.show();
        }    
        else
        {
            if($(this).hasClass('checked'))
            {
                $(this).removeClass('checked');
                var checkedClasses = buttons.filter('.checked').toArray().map(function(btn){return $(btn).data('filter');});
                if(checkedClasses.length == 0)
                {
                    buttons.removeClass('checked'); 
                    targets.show();
                }
                else
                {
                    checkedClasses = $.grep(checkedClasses, function(n, i){ return n != value }),
                    selector = '.' + checkedClasses.join('.'),
                    show = targets.filter(selector);      
                    targets.not(show).hide();
                    show.show();
                }                
            }
            else
            {
                $(this).addClass('checked'); 
                var checkedClasses = buttons.filter('.checked').toArray().map(function(btn){return $(btn).data('filter');}),
                selector = '.' + checkedClasses.join('.'),
                show = targets.filter(selector);      
                targets.not(show).hide();
                show.show();
              
            }
        }   
    });
});
about 4 years ago · Juan Pablo Isaza
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