I have HTML code similar to
<div class="menu">
<div>Latest</div>
<div>Oldest</div>
</div>
I loop through all items in JavaScript and bind a click event listener on them. Now in the event callback, I’d like to know what data to fetch via AJAX. How do I figure that out from one item? I know that I should put something in the item to determine the type of item, but where do I put it?
If you’re using just
divs, using aclassNamewould be convenient and valid. Like this:If you’re using html5, an even better solution would be using custom data- attributes; like this:
The most elegant solution would be using
atags instead of thedivs and intercept their clicks: