Select first child
Description
The following code shows how to select first child.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {<!--from ww w . j a va 2 s. co m-->
$("#container").click(function(e) {
var $ch = $(e.target).children();
$("#results span:first").text($ch.length);
e.preventDefault();
return false;
});
});
</script>
</head>
<body>
<div id="container">
<div>
<p>
This <span>is the <em>way</em> we
</span> write <em>the</em> demo,
</p>
</div>
</div>
<span id="results">Found <span>0</span> children in <span>TAG</span>.
</span>
</body>
</html>