I'd like to make "this" refer to the element which is actually firing the event:
<div class="input-group">
<span class="input-group-addon header-text" id="action-header-text">Action</span>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="action-dropdown" data-toggle="dropdown" aria-expanded="true" style="min-width:250px;">
<span class=" caret">
</span>
</button>
<ul id="action-menu" class="dropdown-menu" role="menu"></ul>
</div>
</div>
Filling Ajax Request:
function UpdateActionDropdown() {
$.ajax({
url: 'FrontEnd/Action',
type: 'POST',
dataType: 'json',
data: {
lid: document.getElementById('selected-language-id').value
},
success: function (data) {
document.getElementById('action-dropdown').firstChild.data = data.UnSelectable[0].ActionTrailer.DescriptionText;
$('#action-menu').html(null);
for (var i = 0; i < data.UnSelectable.length; i++) {
$('#action-menu').append("<li role='presentation' class='disabled'><a role='menuitem' tabindex='-1'>" + data.UnSelectable[i].ActionTrailer.DescriptionText + "</a></li>")
}
$('#action-menu').append("<li role='presentation' class='divider'></li>");
for (var i = 0; i < data.Selectable.length; i++) {
$('#action-menu').append("<li role='presentation'>" +
"<a role='menuitem' tabindex='-1' text='" + data.Selectable[i].DescriptionText + "' value='" + data.Selectable[i].ActionTrailer.ID + "'\" href='#'>" + data.Selectable[i].ActionTrailer.DescriptionText + "</a></li>")
}
}
});
}
global listener:
$('.dropdown').on('click', '#action-menu li', function(){
// Inside here I want to access the li-element which got clicked.
});
I assume that "this" inside the onclick Handler would refer to the document (or window) itself - is it possible to refer to the actual event firing element?
Thanks in advance!