Js gets the outermost element of the currently clicked element

is there any easy way for js to get the outermost element of the currently clicked element?

Jul.02,2022

Recursive

function getRootParent(dom){
    var root = dom;
    if(root.parentNode){
        root = getRootParent(root.parentNode);
    }
    
    return root;
}

click= fn(e) {
 e.target.parentNode
}

if you don't mind using jQuery, you can use


body<br>MouseEvent

//,eventfind
event.path.find(dom=>dom.className.includes('parent'));
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-1b38a73-4ed96.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-1b38a73-4ed96.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?