a/20259055/1636522

by wared

HTML

//Note:First creat the new  automatic  another li elemnt by pressing the enter button when the blinking  mouse is after "link text" li.The id of the new li element created by ol will be the same

<div id="txtarea" contenteditable="true">Some text</div>

JavaScript

var uid = function (uid) {
    return function () {
        return 'item-' + (++uid);
    };
}(0);

document.addEventListener('DOMNodeInserted', function(event){
    var el = event.target;
    if ((el.tagName + '').toLowerCase() === 'li') {
        el.setAttribute('id', uid());
    }
});

$('#txtarea').html(
    '<ol><li id="' + uid() + '">Some text</li></ol>'
);