I have div element with dynamic Id.
<div id="parent">
<div id="elmn1"></div>
<div id="id-has-changed"></div>
<div id="elmn3"></div>
<div id="elmn4"></div>
<div id="id-has-changed-by-user-from-input-field"></div>
</div>
All element id
(except #parent) are editable by user from an input field, so the last child of #parent may has new id set by user.
I want to check the element with the highest number (4
) at the last part of their id
and I want to append a new element with the next id
.
var nextId = "elmn" + (numberOfLastElement + 1);
var newElmn = document.createElement("div");
newElmn.id = nextId;
document.getElementById("parent").appendChild(newElmn);
In this paricular case the new element will has id="elmn5"
.
My question is, how to get numberOfLastElement
?
parent