Skip to content

Creates a nested change #87

@SimonPhilpott

Description

@SimonPhilpott

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions