- jQuery Tutorial
- jQuery - Home
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery DOM Manipulation
- jQuery - DOM
- jQuery - Add Elements
- jQuery - Remove Elements
- jQuery - Replace Elements
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery Useful Resources
- jQuery - Questions and Answers
- jQuery - Quick Guide
- jQuery - Useful Resources
- jQuery - Discussion
jQuery - is( selector ) Method
Description
The is( selector ) method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector.
If no element fits, or the selector is not valid, then the response will be 'false'.
Syntax
Here is the simple syntax to use this method −
element.is( selector )
Parameters
Here is the description of all the parameters used by this method −
selector − The expression with which to filter.
Example
Following is an example showing a simple usage of this method −
<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src = "https://www.tutorialspoint.com/jquery/jquery-3.6.0.js"> </script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("li").click(function () { if ($(this).is(":first-child")) { $("p").text("This is list item 1"); } else if ($(this).is(".middle0,.middle1")) { $("p").text("This is middle class list"); } else if ($(this).is(":contains('item 5')")) { $("p").text("It's 5th list"); } }); }); </script> <style> .selected { color:red; } </style> </head> <body> <div> <span>Click any list item below:</span> <ul> <li class = "top0">list item 1</li> <li class = "top1">list item 2</li> <li class = "middle0">list item 3</li> <li class = "middle1">list item 4</li> <li class = "bottom0">list item 5</li> <li class = "bottom1">list item 6</li> </ul> <p>FILLER</p> </div> </body> </html>
This will produce following result −
jquery-traversing.htm
Advertisements