JavaScript dynamically generates css selector paths?

1. Business scenario
I"m going to manually trigger a click for any dom and generate the style levels as follows:

< hr > < H2 > html structure: < / H2 >
<html>
    <body>
        <h3></h3>
        <ul>
            <li></li>
            <li></li>
        </ul>
        <ul>
            <li></li>
            <li></li>
        </ul>
        <ul>
            <li></li>
            <li></li>
        </ul>
    </body>
</html>
< H2 > expected result: < / H2 >

html > body > ul:eq (1) > li:eq (1)

the following is the js I wrote that currently only implements the hierarchy and can"t get a few elements to ask for help:

var getClassName = function(event, name) {
  if (event.parentNode && event.parentNode.tagName) {
    return getClassName (
      event.parentNode,
      event.tagName + ">" + (name || "")
    );
  } else {
    return name;
  }
}

document.addEventListener("click",function(event){
    console.log(getClassName (event.target));
})
    
Jan.10,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e55fb9-5a3c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e55fb9-5a3c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?