Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda