Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates a nested change #87

Open
SimonPhilpott opened this issue Oct 22, 2020 · 0 comments
Open

Creates a nested change #87

SimonPhilpott opened this issue Oct 22, 2020 · 0 comments

Comments

@SimonPhilpott
Copy link

SimonPhilpott commented Oct 22, 2020

I've added function to include a href and target when finding and replacing with an anchor link;

The script trips over itself. if I try and find and replace a match within a second previously compiled match;

i.e. Some
and
Some Body

findAndReplaceDOMText(document.getElementById('newsPage'), {
find: 'Some',
wrap: 'a',
wrapClass: 'ClassOne',
wrapTarget: '_blank',
wrapLink: 'http://www.linkOne.com'
});

findAndReplaceDOMText(document.getElementById('newsPage'), {
find: 'Some Body',
wrap: 'a',
wrapClass: 'ClassTwo',
wrapTarget: '_blank',
wrapLink: 'http://www.linkTwo.com'
});

Outputs

<a class="ClassOne" href="http://www.LinkOne.com" target="_blank"><a class="ClassTwo" href="http://www.LinkTwo.com" target="_blank">Some</a></a>
<a class="ClassTwo" href="http://www.LinkTwo.com" target="_blank"> Body</a>

A more elegant solution would be be to have the replace on 'Some' not happen.

<a class="ClassOne" href="http://www.LinkOne.com" target="_blank">Some</a>
<a class="ClassTwo" href="http://www.LinkTwo.com" target="_blank"> Body</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant