I am facing an issue with returning a value from a function. It seems like a simple task - just looping through my HTMLElements
and returning the one I need.
This problem is new to me, and I have spent a considerable amount of time debugging the code and trying different approaches to make it work or understand why it's not working as expected.
Any help and insight would be greatly appreciated.
Below is the snippet of the function that I am calling from an event listener triggered by RXjs - fromEvent
I believe the code is fairly self-explanatory, but if you require more details, I can provide my entire code.
function findElementByDataValue(target: EventTarget, data: {key: string, value: string}){
// attempting to return from a function
function send(element) {
return element;
}
if(target && target.dataset){
if(target.dataset[data.key] === data.value) {
// console.log(target);
// send(target);
return target;
} else {
if(target.children){
for (const child in Object.entries(target.children)) {
const element = target.children[child];
findElementByDataValue(element, data);
}
}
}
}
}
You can view the complete code on StackBlitz
*Function called at line:*
65
*Function definition at line:*
34