get index vanilla js code example
Example: get index vanilla js
function index(el) {
if (!el) return -1;
var i = 0;
do {
i++;
} while (el = el.previousElementSibling);
return i;
}
function index(el) {
if (!el) return -1;
var i = 0;
do {
i++;
} while (el = el.previousElementSibling);
return i;
}