:visible
SelectorYou can use the jQuery :visible
selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden;
or opacity: 0;
, because they preserve space in the layout even they are not visible to the eye.
Let's check out an example to understand how this selector basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Test If an Element is Visible</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
// show hide paragraph on button click
$("p").toggle("slow", function(){
// check paragraph once toggle effect is completed
if($("p").is(":visible")){
alert("The paragraph is visible.");
} else{
alert("The paragraph is hidden.");
}
});
});
});
</script>
</head>
<body>
<button type="button">Toggle Paragraph Display</button>
<p style="display: none;">Lorem ipsum dolor sit amet adipi elit...</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel 8 get all Files in Directory Example
You may want to get images from server a...How to Get Portion of URL Path in JavaScript
Use the window.location Object You ca...Laravel 8 Multiple Authentication Tutorial example
If you are building an application which...How To Set up SSH Keys on a Linux Server
SSH or Secure Shell is network protocol...jQuery sliding effect example
In this article, we will describe on sli...