JSFiddle - React, Tailwind, and code Playground
by Ashkan codecman
HTML
<div class="clickTest" id="clickTest1">click Me</div>
<div class="clickTest" id="clickTest2"><span>click Me</span></div>
CSS
body {
display: flex;
justify-content: center;
align-items: center;
color: white;
flex-direction: column;
}
.clickTest {
background-color: dodgerblue;
display: inline-block;
padding: 1rem;
border-radius: 5px;
cursor: pointer;
user-select: none;
margin: 5px;
}
span {
display: inline-block;
}
JavaScript
$('#clickTest1').click(function () {
$(this).html($(this).html() == 'click Me' ? 'clicked' : 'click Me');
});
$('#clickTest2, #clickTest2 > span').click(function () {
$(this).children().css('display', $(this).children().css('display') == 'inline-block' ? 'none' : 'inline-block');
});