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()
- {
- //Example with set of div elements. $('div') means the entire div in the current document.
- //return true, because at-least one div element in the set of div elements has the id '#div1'
- alert($('div').is('#div1'));
- //return false, because none div element in the set of div elements has the id '#div5'
- alert($('div').is('#div5'));
- //return false, because none div element in the set of div elements is hidden.
- alert($('div').is(':hidden'));
- /*Example to use the is() method with single element. Here the expression/filter checked
- with given element only.*/
- //return true, because the given div element div1 is visible, not hidden.
- alert($('#div1').is(':visible'));
- //now hide the div1 element, and check again.
- $('#div1').hide();
- //now it will be false, because the div1 element is hidden.
- alert($('#div1').is(':visible'));
- });
- </script>
- </body>
- </html>
Thank you!

Join the conversation! Your thoughts help the community grow.