JSFiddle - React, Tailwind, and code Playground

by Felipe Alfaro

HTML

<div class="dropDown" data-key="A-a">
a
</div>
<div class="dropDown" data-key="B-b">
b
</div>
<div class="dropDown" data-key="C-c">
c
</div>
<div class="dropDown" data-key="D-d">
d
</div>

JavaScript

document.addEventListener("DOMContentLoaded", function(event) {
    
    var drop = document.getElementsByClassName('dropDown');
		
    for ( i=0; i<drop.length; i++ ){
    
    		drop[i].addEventListener('click',function(){
        		console.log( this.getAttribute("data-key") )
        },false)
        
    }
    
});