Detect if an element is hidden or visible in jQuery-javascript?


I am trying to check if Ads are visible or not(blocked) when user loads my web-application page, if not show a message, which is already hidden by default,so how can I detect if an element is visible in the current page after loading it, and if is not-visible make it visible(some other div to show user's a message to load ads on my website and support us) using jQuery or javascript?

Also is it possible to toggle the visibility of an element, using the function toggle() or any other function?

Thanks


Asked by:- manish
1
: 155 At:- 8/29/2017 8:09:52 AM
javascript jQuery visibility






1 Answers
profileImage Answered by:- vikas_jk

I am not sure if you approach about ads is good or not, but to detect if an element is visible or not using jquery you can use the code below

$(element).is(":visible"); 

Or if there is any class of element which you want to test then you can apply this code

$(".Class").each(function() {
    if ($(this).css("visibility") == "hidden") {
        // code to handle non-visible state
    } else {
        // code to handle visible state
    }
});

You can use any of the above methods

About changing the state of element, yes after applying the above code, you can easily change the state, as per your needs using .show() or .hide()

0
At:- 8/29/2017 3:12:17 PM Updated at:- 8/29/2017 3:12:42 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use