I'm bringing backend notifications and I need to dynamically add the path to them, how do I add a <li>
to each response element?
JavaScript
$(document).ready(function () {
$.ajax({
url: "/tasks/not-assign",
dataType: "JSON",
success: function (res) {
for(var i = 0; i<res.length; i++) {
$('#taskItem').html(res[i].title);
var a = document.getElementById('taskItem'); //or grab it by tagname etc
a.href = "/tasks/detail/" + res[i].id;
}
}
});
});
HTML
<li>
<a href="#" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false" style="color: #fff"><i class="fa fa-bell-o" aria-hidden="true"></i><span id="numberTask" class="badge"></span></a>
<ul class="dropdown-menu">
<li><a id="taskItem"></a></li>
</ul>
</li>
The way it is, it only has the last item in the collection, so I need to add <li>
dynamically.