tags:

views:

53

answers:

4

Hi guys,

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

A: 

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

No it doesn't, it only displays Hello

ILMV
A: 

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

Raja
Thanks very much for the heads up. It looks like a great site
AtiKuSDesign
A: 

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.

Jeriko
+2  A: 

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();
karim79
Thanks very much. I actually need it in an if statement, which is why I was using the is.I have it working now. YAY!
AtiKuSDesign