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:
  1. <html>
  2. <body>
  3. <!-- Set of div elements with different id -->
  4. <div id="div1">Div1</div>
  5. <div id="div2">Div2</div>
  6. <div id="div3">Div3</div>
  7. <div id="div4">Div4</div>
  8. <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
  9. <script>
  10. $(function()
  11. {
  12. //Example with set of div elements. $('div') means the entire div in the current document.
  13. //return true, because at-least one div element in the set of div elements has the id '#div1'
  14. alert($('div').is('#div1'));
  15. //return false, because none div element in the set of div elements has the id '#div5'
  16. alert($('div').is('#div5'));
  17. //return false, because none div element in the set of div elements is hidden.
  18. alert($('div').is(':hidden'));
  19. /*Example to use the is() method with single element. Here the expression/filter checked
  20. with given element only.*/
  21. //return true, because the given div element div1 is visible, not hidden.
  22. alert($('#div1').is(':visible'));
  23. //now hide the div1 element, and check again.
  24. $('#div1').hide();
  25. //now it will be false, because the div1 element is hidden.
  26. alert($('#div1').is(':visible'));
  27. });
  28. </script>
  29. </body>
  30. </html>
For more details and live demo with source code
Thank you!