onEventCase2
onEventCase2
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>
$element = "#2";
$("#1").on(
"click",
function() {'"'+$element+'"'}, // <-- child Selector
function() {
$("#1")
.find('span')
.filter(function() {
return $(this).text() === 'a';
})
.css('background-color', 'red');
}
);
</script>
</body>
</html>