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
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()
You can also check if element is hidden or visible using below jQuery code
$('element:hidden')
$('element:visible')
Example, if we are trying to check HTML element with id "checkme"
if($('#checkme:hidden')){
//element hiddent
}
if($('#checkme:visible')){
//element visible
}
Thanks
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly