I have a question. How can I use the parentNode property multiple times?
I know that I can make something like this:
document.getElementById("mytag").parentNode.parentNode.remove();
Or something like this. My Problem is not that I can add more or less .parentNode to remove whatever I want to remove.
My Problem is that I want to create a user friendly app in which the user can self declare how many parentNodes should be removed.
At first I tried to add .parentNode by a loop. It doesn't work. At second I tried the same with the eval() function. Same result.
Is there a person who have a good solution how I can make this? It was very useful if there is a opportunity on which you only have to say the number of parentNodes.
Here a little example. What I will be done "automatically":
myFunction(..., ..., 3) {
...
document.getElementById("mytag").parentNode.parentNode.parentNode.remove();
}
Or
myFunction(..., ..., 2) {
...
document.getElementById("mytag").parentNode.parentNode.remove();
}
Or
myFunction(..., ..., 1) {
...
document.getElementById("mytag").parentNode.remove();
}
Thank you very much.
I prefere a solution in pure JS. An additional jQuery solution would be also nice.