Sunday, February 17, 2019

regex - Reverse DOM traversing with JavaScript

I am curious to know if one could search the entire DOM with a regex that could then essentially identify the path used to get to the matching node. So in other words, I want to find all matches of a pattern, lets say the words "hello" and from that I want to identify its branching within the DOM or the container parent at least.



Applying the regex match obviously finds the matches, but neglects to keep the context of where they were found within the DOM. Is there a way to override this matching to also print or associate the location of the match? If not (assuming a regex will not parse the DOM tree in the same fashion), are there any suggestion to achieve the desired results?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...