First of all I do not want to use jQuery, just pure javascript; please don't link to duplicate jQuery posts.
If I have a list like
<ul id=bulk>
<li id=one></li>
<li id=bmw></li>
</ul>
I want to get the id of the clicked list element.
I am aware I could add onClick= to each element but the production list I have has 2000 entries and I think a better way exists.
For example:
If I had only one li
element with id='singular'
I could use the following javascript to get the ID clicked.
var li = document.getElementById('singular').onclick = function() { do something };
As there are thousands of li
elements, this code won't work.
I have been able to get a list of the element names with the following javascript:
var bulk = document.getElementById('bulk');
var bulkli = tabs.getElementsByTagName('li');
//bulkli contains [one, bmw];
but this does not tell me which one was clicked.