The jQuery is() method will return a boolean value(true/false) by checking the given element or set of elements against an expression or filter. The method will return true, if the given element or at-least one element in the given set of elements is matched with the expression or filter. Otherwise, it will return false.
Example:
- <html>
- <body>
- <!-- Set of div elements with different id -->
- <div id="div1">Div1</div>
- <div id="div2">Div2</div>
- <div id="div3">Div3</div>
- <div id="div4">Div4</div>
-
- <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
- <script>
- $(function()
- {
-
-
-
- alert($('div').is('#div1'));
-
- alert($('div').is('#div5'));
-
- alert($('div').is(':hidden'));
-
-
-
-
-
- alert($('#div1').is(':visible'));
-
-
- $('#div1').hide();
-
- alert($('#div1').is(':visible'));
- });
- </script>
- </body>
- </html>
Thank you!