JQuery is not an error function

When developing with Firebug, I keep getting this error.

pages [x] .css ("z-index", x) is not a function

The function itself works great, but I'm trying to figure out why it continues to celebrate this. The function simultaneously reorganizes the array and z-indices. Can I not access array variables and calls to them like this, or is it something else?

full code:

var pages = $("#use-wrapper").children("div");

pages.children("a.right").click(function(event) {
    event.preventDefault();
    $(this).parent("div").css("z-index","0");
    pages.push($(this).parent("div"));

    for(var x = pages.length; x >= 1; --x) {
        pages[x] = pages[x-1];
        pages[x].css("z-index",x);
    }
    pages[0] = pages.pop();
});
+3
source share
1 answer

If you execute alert(pages[x]), you will find that each pages[x]is a DOM element and not a jQuery object, so you get an error that is pages[x].cssnot a function. You probably want to do:

$(pages[x]).css('z-index', x);

: , jQuery pages, , , , push pop .

+5

Source: https://habr.com/ru/post/1760461/


All Articles