Iterate over the collection of parents using.parents().each(function(){})
on the jquery object, which will walk up the tree:
//use the dollar-sign at beginning if the argument name
//to hint that the fn is expecting a jquery object:
function getDomData($activeElement){
//start with the element that was clicked:
var path = '/' + $activeElement.data('id');
//then go over each ancester up the tree, check which
//type it is, and append to the beginning of your path accordingly:
$activeElement.parents().each(function(){
if($(this).hasClass('list-group-item')){
path = ('/' + $(this).data('id')) + path;
}
else if($(this).hasClass('list-group')){
path = ('/' + $(this).data('type')) + path;
}
});
return path;
};