2

I have some HTML loaded in WebView like this:

<html><head></head><body>before  <myTag>Content</myTag>  after</body></html>

I want to replace element myTag with custom text so it should look like:

 <html><head></head><body>before  ____MY_CUSTOM_TEXT___  after</body></html>

Also I can't change initial HTML. How I can do this with JavaScript?

My not finished code:

var elements = document.getElementsByTagName( 'myTag' );
var firstElement = elements[0];
var parentElement = firstElement.parentNode;
var html = parentElement.innerHTML;
parentElement.innerHTML = html.replace(?????, '____MY_CUSTOM_TEXT___');

I don't know how to get string value of element to replace (?????).

1 Answer 1

1

Here you go:

var txt = document.createTextNode('____MY_CUSTOM_TEXT___');
parentElement.replaceChild(txt, firstElement);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.