I am trying to get the selected value from a div element which is dynamically populated with a dropdown li. This is on an existing website so we use additional javascript to add listeners to the div. See attached code as example. When I click on "red s" area, I only get part of the html. Ideally I want the entire text "red shoes" which I only get if I click on the "hoes" area. How do I get the entire text of the li element which is clicked?
For example:
function getEventTarget(e) {
e = e || window.event;
return e.target || e.srcElement;
}
var ul = document.getElementById('search_suggestion');
ul.onclick = function(event) {
var target = getEventTarget(event);
alert(target.innerHTML);
};
<div id="search_suggestion">
<ul class="suggestion_keyword">
<li><span class="keywords">red s</span>kirt
<div class="brm-autosuggest-nub"></div></li>
<li><span class="keywords">red s</span>horts</li>
<li><span class="keywords">red s</span>hoes</li>
<li><span class="keywords">red s</span>hirt</li>
</ul>
</div>