Reputation: 253
Why this code is not working? Meaning nothing get displayed into the ul tag.
$("#server").each(function()
{
var textValue = $(this).text();
$('#list li').eq(counter).append('<li>' + textValue + '</li>'); // <-- not working
$('#list li').eq(counter).insertAfter('<li>' + textValue + '</li>'); // <-- or not working
$('#list')append('<li>' + textValue + '</li>'); // <-- or working
});
<div>
<ul id="list"></ul>
</div>
Upvotes: 0
Views: 78
Reputation: 707696
I think your full answer is here in your previous question on this topic (read the comments to your questions in my answer).
I think you want jQuery's method .after()
instead of .insertAfter()
. Full working example including a jsFiddle here.
$('#list li').eq(counter).after('<li>' + textValue + '</li>');
Upvotes: 0
Reputation: 4070
I see two problems.
$('#list li')
doesn't resolve to anything since there is no <li>
yet. It should be ul
instead.eq
during iteration, you may want to pass in the current index into the functor, like so: $('#server').each(function(counter){...
- but maybe counter
comes from somewhere else, that's not clear from your posting.Regards db
Upvotes: 0
Reputation: 19290
#server
can only match a single element.counter
is undefined.#list
does not contain any items, so #list li
will not match anything.append
.Upvotes: 2