Hi,
I have created a scrollable listbox. When I click on the last element
in the listbox, it calls the appropriate method (Method A) . If I then
use the scroll bar to navigate back to the top of the list, it calls
method A each time I click on the scroll bar. This is because the
onclick event handler is on the entire list box. How do I ensure that
the event handler is only called when I click on the selected element
of the list box? Below is snippets from my code
function displayListBox(){
//Get the listbox
var listbox = document.getElementById('listbox');
addItemToListBox(listbox);
....
listbox.addEventListener("click", handleOnClickEvent, true);
....
}
function addItemToListBox(listbox){
//Create new list item
listItem = document.createElement('listitem');
....
listItem.setAttribute("reacttoclick", "true");
....
listbox.appendChild(listItem);
}
function handleOnClickEvent(e){
var element = e.currentTarget;
var selected = element.selectedItem;
....
}
Thanks in advance for your help.
|