I have created a dynamic list <ul> <li> aa bb cc </li> </ul>
. as you can see here. from this link, I could get the whole clicked row. that is fantastic! My question is , how could I get the name of the person? like, I want to alert just murat
, not the whole thing. alert($(this).html().name)
not worked..
Asked
Active
Viewed 47 times
-3

Barmar
- 741,623
- 53
- 500
- 612

user3252936
- 27
- 8
-
Post your code here, not just at a remote site. You can use [Stack Snippets](https://stackoverflow.blog/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) to make it executable. – Barmar Aug 23 '17 at 20:47
-
`.html()` returns a string, what do you expect `.name` to return from that? – Barmar Aug 23 '17 at 20:47
-
You can use `String.prototype.split` to split a string into words separated by spaces. Or you can use a regular expression to parse a more complex pattern. – Barmar Aug 23 '17 at 20:50
1 Answers
0
function LoadEmployees() {
var ul = $("#employees");
ul.empty();
$.ajax({
method: "GET",
url: "../api/employee/employeelist"
}).done(function (response) {
// console.log(response);
if (response == null) return;
for (var i = 0; i < response.length; i++) {
var emp = response[i];
var li = $(" <li class='list-group-item' id="+emp.id+">" + emp.id+" " + emp.Name + " " + emp.Surname +
"(Cinsiyet:" + emp.Gender + " Maaş : " + emp.Salary + "$)</li>")
.click(function () {
//I THİNK I SOLVED MY PROBLEM. HOWEVER, NOW, I AM TRYİNG TO SET THE COMBOBOX BASED ON CLİCKED İTEM. I UPDATED
$('#name').val(response[$(this).index()].Name);
$('#surname').val(response[$(this).index()].Surname);
$('#gender').val(response[$(this).index()].Gender);
$('#salary').val(response[$(this).index()].Salary);
// alert($(this).html()); // gets innerHTML of clicked li
// alert(this.id);
});
ul.append(li);
}
}).fail(function () {
alert("Hata oluştu.")
});
}

user3252936
- 27
- 8