I am trying to build a very simple functionality to create a drop down under a certain text field when its clicked.
$(".val").children("div").on("click", function() {
alert("CLICK");
});
.container {
display: inline-block;
}
.val {
display: none;
position: absolute;
z-index: 1;
}
.container:focus-within .val {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="lab" contenteditable>LABEL</div>
<div class="val">
<div>VAL1</div>
<div>VAL2</div>
</div>
</div>
Main problem comes with the click function which it never gets triggered... (I guess it runs first the lost focus in CSS and then no click is done in that element as its hidden?)
Even though there is an "alert" there, I want to use the click event to set the value back in the .lab field like a dropdown.