- jQuery Examples
- Examples - Home
- Examples - Set up
- Examples - Selectors
- Examples - Attributes
- Examples - Traversing
- Examples - CSS
- Examples - DOM
- Examples - Events
- jQuery Useful Resources
- jQuery - Quick Guide
- jQuery - Useful Resources
jQuery Examples - $("li > ul")
Description
"$("li > ul")" Selects all elements matched by <ul> that are children of an element matched by <li>.
Syntax
Here is the simple syntax to use this selector −
$("classname > child-element")
Parameters
Here is the description of all the parameters used by this selector −
classname − class of the container element
child-element − descendent of element that has an id of container.
Returns
Like any other jQuery selector, this selector also returns an array filled with the found elements.
Example
<html> <head> <title>The Selector Example</title> <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { /* Selects all elements matched by ul that are children of an element matched by li.*/ $("li > ul").css("background-color", "yellow"); }); </script> </head> <body> <ul> <li class="big">This is first list item of the DOM.</li> <li class="medium">This is second list item of the DOM. <ul> <li class="big">This is first sub list item of the DOM.</li> </ul> </li> <li class="small">This is third list item of the DOM.</li> </ul> </body> </html>
This will produce following result −
jqueryexamples_selectors.htm
Advertisements
To Continue Learning Please Login
Login with Google