Originally I was just doing that listener somewhere in the .js files that load initially. It wasn't working. I moved the listener declaration to within the function that actually calls the replaceWith function and put it after the replaceWith command and now it works.
This means that now it will be declared whenever the function containing the replaceWith function is called and the content changes but it works. Is that the only way this works?
I suspect that when I was doing it originally, the anchor tag didn't exist. So I dynamically added the anchor tag and the event listener didn't recognize it. Is that what is happening?