I have an unordered list that I am prepending data to as follows:
jQuery("#mylist").prepend(newItem);
When the list reaches a certain size I need to remove the first item that was inserted before adding the new one.
How would I get the first item to remove based on accessing the ordered list by it's id.
Something like:
jQuery("#mylist")[0].remove();
Thanks
Since you mentioned ordered list, im assuming #mylist contains li tags inside, thus this should work
jQuery("#mylist li:first-child").remove();
I see you are prepending there, In case you want to remove the last element then
jQuery("#mylist li:last-child").remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With