JSFiddle - React, Tailwind, and code Playground

HTML

<ol class="nested">
    <li id="list_1">a</li>
    <li id="list_2">
        <ol>
            <li id="list_3">b</li>
            <li id="list_4">c</li>
        </ol>
    </li>
    <li id="list_5">d</li>
</ol>

CSS

ol {margin-left: 10px}

JavaScript

var parent_ID=1;
if ($('#list_'+parent_ID+' ol').length > 0) {
  $('#list_'+parent_ID+' ol > li:last-child').after('<li id="">x</li>');
} else {
  $('#list_'+parent_ID).append('<ol><li id="">x</li></ol>');
}