I have an <ol> (saved to Var1) and would like to be able to assign its last <li> element to a variable.
I tried doing the following:
Lastli = var1.lastChild
However, it doesn’t seem to work.
I’d like to do this with vanilla JS, and no jQuery.
You can select the parent element and use the
lastChildproperty.Or you select all the items into an array and get the last item. Here is a quick example: