Skip to content

Instantly share code, notes, and snippets.

@willhalling
Created August 6, 2013 09:55
Show Gist options
  • Save willhalling/6163259 to your computer and use it in GitHub Desktop.
Save willhalling/6163259 to your computer and use it in GitHub Desktop.
.children() method.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<title>.children() method</title>
<script type="text/javascript">
$(function() {
// children() only travels a single level down the DOM tree while .find() can traverse down multiple levels
$('li').children().css('background','red');
});
</script>
</head>
<body>
<ul id="parent">
<li>Parent 1</li>
<li>Parent 2
<ul id="children">
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ul>
</li>
<li>Parent 3</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment