开发者

Would this jQuery is.(":hidden") work?

开发者 https://www.devze.com 2022-12-27 04:48 出处:网络
I\'m playing around with the \'is\' filter 开发者_开发百科in jQuery and I am currently without the opportunity to use a testing server.

I'm playing around with the 'is' filter 开发者_开发百科in jQuery and I am currently without the opportunity to use a testing server.

What I want to know is...would this work to display both hello and goodbye?

$(document).ready(function(){

    if ($("p").is(':visible')) {
        $(this).css('display','block');
    }

});

<p>hello</p>
<p style="display:none">goodbye</p>

Basically what I want to do is run an action on something when it is visible but not run it when it isn't.

Thanks guys


Basically what I want to do is run an action on something when it is visible but not run it when it isn't.

I think you mean that you're trying to execute something on one or more visible elements? Then you would just need to use the visible filter within your selector:

$("p:visible").doSomething();


Here is your answer --> http://jsfiddle.net/5FrGn/1/

No it doesn't, it only displays Hello


For these types of try outs use jsfiddle.net. It is an awesome site which would enable to work with multiple JS libraries at one go.

HTH


What your code is saying, basically, is that whenever any visible paragraph is clicked, it's made visible. I'm pretty sure that's not what you're trying to achieve...

However, yes, the concept is right - if you try $(element).is(":visible") it returns true if the element is visible, and false otherwise.

0

精彩评论

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