The easiest way to do this would be to attach event listeners to each of the elements and then use the .fadeToggle() method to show/hide the corresponding element.
Example Here
$('#a1').on('click', function () {
$('#b1').fadeToggle();
});
$('#a2').on('click', function () {
$('#b2').fadeToggle();
});
Since this could get relatively redundant, you could simplify it to the following:
Example Here
var mapping = {
'a1': 'b1',
'a2': 'b2'
}
$('.head_dd [id]').on('click', function () {
$('#' + mapping[this.id]).fadeToggle();
});
Without jQuery:
You could also use plain JavaScript and CSS3 transitions:
var mapping = {
'a1': 'b1',
'a2': 'b2'
}
Array.prototype.forEach.call(document.querySelectorAll('.head_dd [id]'), function (el) {
el.addEventListener('click', function () {
document.getElementById(mapping[this.id]).classList.toggle('visible');
});
});
.bt1int {
opacity: 0;
transition: opacity 1s;
}
.visible {
opacity: 1;
}
<div class="wrap">
<ul class="head_dd">
<li id="a1">a1</li>
<li id="a2">a2</li>
</ul>
</div>
<div class="bt1int" id="b1">b1</div>
<div class="bt1int" id="b2">b2</div>