The ':visible Selector' is used to select the elements, which are not hidden.
i.e. There is a CSS property called 'display:none;'. If that is set the element would not be shown and is said to be hidden.
Let us simplify with the below example.
<html>
<head>
<title> My First Programme </title>
</head>
<body>
<h1> JQuery </h1>
<div class = "newClass">
<p class = "para1"> First Paragraph </p>
<p class = "para2"> Second Paragraph </p>
<p style = "display:none;" class = "para3"> Third Paragraph </p>
</div>
<button> Click me </button>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$('button').click( function() {
$('p:visible').text("These p elements are visible")
});
</script>
</body>
</html>
So, if you see the above code. We can see that there are three <p> elements,
<div class = "newClass"> <p class = "para1"> First Paragraph </p> <p class = "para2"> Second Paragraph </p> <p style = "display:none;" class = "para3"> Third Paragraph </p> </div>
And the third <p> element is hidden,
<p style = "display:none;" class = "para3"> Third Paragraph </p>
And the first two <p> elements are visible.
<p class = "para1"> First Paragraph </p> <p class = "para2"> Second Paragraph </p>
And on button click, the contents of first and second <p> element is changed.
And this happened with the '$('p:visible')' element selector.
$('button').click( function() {
$('p:visible').text("These p elements are visible")
});The moment the button is clicked, JQuery statement gets triggered.
$('p:visible').text("These p elements are visible")And the contents of first two <p> elements are changed.
<p class = "para1"> First Paragraph </p> <p class = "para2"> Second Paragraph </p>