Suppose I have a container containing a list of elements, so the markup looks something like
<div class="container"> <div class="list-item" id="item-1"> ....</div> <div class="list-item" id="item-3"> ....</div> <div class="list-item" id="item-2"> ....</div> <div class="list-item" id="item-6"> ....</div> </div>
Suppose the container and the elements have a reasonable distance, so you can click in the space between the two elements. I want to capture this click and then insert the new editable list item that the user clicked into. To be able to insert a new list item, I need to know either the item to be inserted after, or earlier.
I can catch this click on the container class. But after...
I would like to get a position from a click, and most importantly: I would like to get the closest (surrounding) list-item so that I can insert a new list-item .
Does anyone know how to do this?
source share