There are several links/images on a website. I have a box that popups when you click on a link/image. Now the other links/images should "dim out" while the one clicked should stay the same. Currently I have following script:
HTML Boxcontent
<div id="boxid1" class="modal-box">
Content Box 1
</div>
<div id="boxid2" class="modal-box">
Content Box 2
</div>
HTML Links
<div class="container a">
Content
<a class="linkid1">Test</a>
</div>
<div class="container b">
Content
<a class="linkid1">Test</a>
</div>
CSS
.modal-box { display: none; }
.dim { background: blue; }
$('.linkid1').click(function(e){
$('.container').not('.a').toggleClass('dim');
$('#boxid1').toggle();
});
$('.linkid2').click(function(e){
$('.container').not('.b').toggleClass('dim');
$('#boxid2').toggle();
});
This works but very possibly (I'm a novice) is bad and too "complicated". How can I streamline this?
Follow Up: Would this also be possible to achieve without javascript and just css? Like https://jsfiddle.net/wcvtesor/ but with the "features" described above