I have this dropdown menu
<ul class="dropdown-menu"></ul>
whose <li>
items are populated by jquery from a database table
success:function(data){
$(".dropdown-menu").empty();
$.each(data, function(key, value){
$(".dropdown-menu").append("<li>" + key + "</li>");
});
I want to get the text of the <li>
item clicked on by the user.
I have tried
$(document).ready(function () {
$(".dropdown-menu").click(function(){
var sel=$(".dropdown-menu .selected").text();
alert(sel);
});
});
I have tried the solutions in
- jQuery Get Selected Option From Dropdown
- How to get value of selected dropdown value on button click in jquery
- Get selected text from a drop-down list (select box) using jQuery
and several others to no avail.
The alert box is coming up blank.
How can I get the value of the clicked item? I cannot use the select option
.
Thank you