var element; //your clicked element while(element.parentNode) { //display,log or do what you want with element element = element.parentNode; }