JSFiddle - React, Tailwind, and code Playground
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>parents demo</title>
<style>
p, div, span {
margin: 2px;
padding: 1px;
}
div {
border: 2px white solid;
}
span {
cursor: pointer;
font-size: 12px;
}
.selected {
color: blue;
}
b {
color: red;
display: block;
font-size: 14px;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>
<div>
<div><span>Hello</span></div>
<span>Hello Again</span>
</div>
<div>
<span>And Hello Again</span>
</div>
</p>
<b>Click Hellos to toggle their parents.</b>
<script>
function showParents() {
$( "div" ).css( "border-color", "white" );
var len = $( "span.selected" )
.parents( "div" )
.css( "border", "2px red solid" )
.length;
$( "b" ).text( "Unique div parents: " + len );
}
$( "span" ).click(function() {
$( this ).toggleClass( "selected" );
showParents();
});
</script>
</body>
</html>