开发者

Storing jquery selector arrays?

Below you can see that I store the results of the jquery selector in an array. I then use this array to perform other functions. This example here doesn't seem to work, it's behaving as if the var/array is a live selector, not the results when they were instantiated.

function flipIt(elementId){
    if (window.jQuery){
        var thisVisibleArray = $('#' + elementId + ' div:visible');

        var thisInvisibleArray = $('#' + elementId + ' > div:visible');

        $(thisInvisibleArray).slideDown("fast");
        $(thisVisibleArray).slideUp("fast");


        /*
        if ($('#flip1').is(":visible")){
            $('#flip1').slideUp("fast", function(){
                $('#flip2').slideDown();
            });
        } else {
            $('#flip2').slideUp("fast", function(){
              开发者_开发百科  $('#flip1').slideDown();
            });
        }*/
    }
}


In order to select the invisible div elements you have to use not and not ">". And also the 2 variables you defined are already jquery element array so you dont have to use $(). Try this

function flipIt(elementId){
if (window.jQuery){


    var thisVisibleArray = $('#' + elementId + ' div:visible');

    var thisInvisibleArray = $('#' + elementId + ' div:not(:visible)');

    thisInvisibleArray.slideDown("fast");
    thisVisibleArray.slideUp("fast");


    /*if ($('#flip1').is(":visible")){
        $('#flip1').slideUp("fast", function(){
            $('#flip2').slideDown();
        });
    } else {
        $('#flip2').slideUp("fast", function(){
            $('#flip1').slideDown();
        });

    }*/
}
}


You are storing the selected elements in a variable, and then you are trying to get a jQuery object out of another jQuery object. Just do:

thisInvisibleArray.slideDown("fast");
thisVisibleArray.slideUp("fast");

Also, they are not arrays, but jQuery objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜