hankknight
asked on
jQuery: Find matching children but not matching grandchildren
Using jQuery, how can I select matching children but not matching grandchildren?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Examples</title>
<style type="text/css">
li {
cursor: pointer;
}
ul ul {
display: none;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('li').click(function () {
$(this).find('ul').show()
});
});
</script>
</head>
<body>
When you click on "Vegitation" only "Fruit" and "Vegies" should be shown. "Apple" and "Peas" should not be shown.
<ul>
<li>Vegitation
<ul>
<li>Fruit
<ul>
<li>Apple</li>
<li>Peach</li>
<li>Pear</li>
</ul>
<li>Vegies
<ul>
<li>Spinich</li>
<li>Peas</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window