In the findParentByClassName function below, currentParent is returning undefined. Can someone tell me why? I think it's actually returning undefined in getSongItem, clickHandler and HTML TableRowElement as well.
This is where the problem seems to be occuring.
var findParentByClassName = function(element, targetClass) {
if (element) {
if (element.parentElement && element.parentElement.className) {
if (element.parentElement === null) {
console.log("No parent found");
} else if (element.parentElement.className !== targetClass) {
console.log("No parent found with that class name.");
} else if (element.parentElement !== null &&
element.parentElement.className === targetClass) {
var currentParent = element.parentElement;
}
while (currentParent.className !== targetClass && currentParent.className !==
null) {
currentParent = currentParent.parentElement;
}
//I need to know why currentParent is returning undefined
return currentParent;
}
}
};
There may be a problem here as well.
var getSongItem = function(element) {
switch (element.className) {
case 'album-song-button':
case 'ion-play':
case 'ion-pause':
return findParentByClassName(element, 'song-item-number');
case 'album-view-song-item':
return element.querySelector('.song-item-number');
case 'song-item-title':
case 'song-item-duration':
return findParentByClassName(element, 'album-view-song-item').querySelector('.song-item-number');
case 'song-item-number':
return element;
default:
return;
}
};