开发者

JQuery visible selector and prev()

I am trying to determine which element with a particular class is visible. Then find its immediate previous element and slide over to it. I tried this but it is not correct.

if($('#sidepanel1').is(':visible')) {
        开发者_Go百科 }
        else { 

        var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id'); alert(prevpanel);

        $('.sidewrapper').hide("slide", { direction: "right" }, 300); $(prevpanel).show("slide", { direction: "left" }, 300);
        }

}

Its something to do with my use of :visible that I think is wrong. Any ideas?

Marvellous


change

var prevpanel = $('.sidewrapper').is(':visible').prev().attr('id');

to

var prevpanel = $('.sidewrapper:visible').prev().attr('id');

the .is() returns bool

Unlike the other filtering methods, .is() does not create a new jQuery object. Instead, it allows you to test the contents of a jQuery object without modification.


if($("#sidepanel1").css("visibility") == "visible")
{
 // do stuff
}


According to the docs, is() would only return a boolean value in that case. It doesn't return another instance of the jQuery object, so your chain is broken.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜