Dynamically replace HTML element in UIWebView
Posted
by Skie
on Stack Overflow
See other posts from Stack Overflow
or by Skie
Published on 2010-04-30T15:33:01Z
Indexed on
2010/04/30
15:37 UTC
Read the original article
Hit count: 190
iphone
|JavaScript
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 (?????).
© Stack Overflow or respective owner