Please check the below JavaScript code
<script>
function dynamicMessageLoader(id) {
$.get("SentMessagesDynamicLoaderServlet?idMessageGroup=" + id, function (responseJson) {
$('#li_list').empty();
var array = [];
$.each(responseJson, function (index, item)
{
array[index] = item;
});
$('#message_count').empty();
var readArray = array.length;
var count = readArray + " Messages Selected";
$('<p />', {html: count}).appendTo('#message_count');
for (var i = 0; i < readArray; i++) {
$('<li />', {html: array[i][0]}).appendTo('#li_list');
}
});
}
</script>
Then some HTML
<ul id="li_list"></ul>
In my JavaScript code, consider this section -
`$('<li />', {html: array[i][0]}).appendTo('#li_list');`
What I want is not to just create a <li> but with its remaining attributes, exactly like below
<li class='clickable-row hand' id="3" >Text here</li>
In my array, array[i][0] contains the ID and array[i][1] contains a text. How can I achieve this?
li, add the classes (.addClass()), add the id (.attr()), add the text (.text()/.html()) and append to the list (.appendTo())