JSFiddle - React, Tailwind, and code Playground
HTML
<!-----Row 1--------->
<div class="row row1">
<div class="row1-2">Simple Text</div>
<div class="row1-2 ToggleClass"> <a href="#">Action</a>
<div class="ActionDropDown">
I am a Drop Down !
</div>
</div>
</div>
<!-----Row 1--------->
<!-----Row 2--------->
<div class="row row1">
<div class="row1-2">Simple Text</div>
<div class="row1-2 ToggleClass"> <a href="#">Action</a>
<div class="ActionDropDown">
I am a Drop Down !
</div>
</div>
</div>
<!-----Row 2--------->
<!-----Row 3--------->
<div class="row row1">
<div class="row1-2">Simple Text</div>
<div class="row1-2 ToggleClass"> <a href="#">Action</a>
<div class="ActionDropDown">
I am a Drop Down !
</div>
</div>
</div>
<!-----Row 3--------->
<div class="InfoDiv">
<b>Info:</b> Right now click on Action on each row open drop down multiple times. What I want is when one drop down is open on click of action , the other drop down if open should get close.
</div>
CSS
* {
margin: 0px;
padding: 0px;
float: left;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
font-family: arial;
}
a {
text-decoration: none;
}
body,
html {
width: 100%;
height: 100%;
background: #cbeeff
}
.row1 {
width: 100%;
background: #fff;
margin: 5px 0;
}
.row1-2 {
width: 50%;
position: relative;
text-align: center;
padding: 10px 0;
border-right: 2px solid #000
}
.row1-2+.row1-2 {
border-right: 0px;
}
.row1-2 a {
color: #ff4886;
float: none;
}
.ActionDropDown {
position: absolute;
background: #7bd4ff;
border: 2px solid #000;
top: 20px;
padding: 30px 10px;
display: none;
z-index: 9;
right: 0px;
left: 0px;
max-width: 180px;
margin: 0px auto;
}
.InfoDiv{ width:100%; padding:10px; background:#ffadc9;}
JavaScript
$('.ToggleClass a').click(function(ev) {
var dropDown = $(this).next('.ActionDropDown')
if ($(dropDown).is(":visible")) {
$(dropDown).fadeOut(500)
} else {
$(dropDown).fadeIn(500)
}
$(this).parents(".row").siblings(".row").find(".ActionDropDown:visible").fadeOut(500)
});
$(document).mouseup(function (e)
{
if (!$(".ActionDropDown").is(e.target) ) // if the target of the click is not the dropDown
{
$(".ActionDropDown").fadeOut(500);
}
});