Sunday 17 February 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...