onEventCase3

by Arthur Tarasov

HTML

<!DOCTYPE html>
<html>
<head>
	<script   
		src="https://code.jquery.com/jquery-3.1.0.min.js"   
		integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="   
		crossorigin="anonymous">
	</script>
</head>
<body>

<span id="1">
	<span id="2">a</span>
	<span id="3">b</span>
</span>

<script>
	$("#1").on(
		"click",
		"#2",		// <-- child Selector
		function() {
	        $("#1")
	        .find('span')
	        .filter(function() {
	        	return $(this).text() === 'a';
	        })
	        .css('background-color', 'red');
    	}
	);
</script>

</body>
</html>