Question

I've got a problem with jQuery in Firefox with the each() function.

$(".pagination").on("click", ".numpag", function() {
    $("input[name='pag'").val($(this).index()+1);
    $(".numpag").each(function() {
        $(this).removeClass("active");
    });
    $(this).addClass("active");
    send_form();
});

So this will remove the Class "active" from the number page where the user is, and will add it to the clicked one. Later on I'll send the function that will give me the results again and the number of pages.

function send_form() {
    //Mostramos la paginacion
    $.ajax({
        type: 'POST',
        url: 'query_ajax.php?pagination',
        data: form,
        success: function(response2) {
            $(".pagination").html(response2);
        }
    });
}

I tried this with Chrome and works fine. But when I tried it with FF it doesn't enters to the each function from jQuery. I've been commenting the lines and adding alerts to know where is failing, and came out in the each.

I've been looking around, and read that FF loads before it is added (the ajax) to the DOM.

How this can be solved?

thanks for your time.

Was it helpful?

Solution

Try to change your code to:

$(".pagination").on("click", ".numpag", function() {
    $("input[name='pag']").val($(this).index()+1);
    $('.numpag').removeClass("active");
    $(this).addClass("active");
    send_form();
});

OTHER TIPS

In order to make sure the jquery code is executed after the DOM is loaded, use

$( document ).ready(function() {
    // something...
});

or the equivalent shorter version:

$(function () {
    // something...
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top