T
T
the5x2020-05-20 21:57:45
JavaScript
the5x, 2020-05-20 21:57:45

How to remove removeChild which is innerHTML without searching querySelector (Angular)?

There is something like this HTML structure:
A parent that contains a child node that is inserted as innerHTML. I need to remove this node, without document.querySelector and document.getElementById . I can’t remove it via element.removeChild(element), because due to the fact that it is innerHTML, I get that the node is not a child. Help solve the problem.

<div class="parent">
   <div class="child">Text</div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-05-20
@hzzzzl

when you insert innerHTML into an element, it will be parsed by the browser, and then you can select the content via parent.querySelector('.child')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question