Javascript : How to replace HTML inside <div>?
Problem :
How to use Javascript to replace the HTML codes?
While attempting to show different content to visitors equipped with Ad block plugin. I need to figure out how to replace the HTML codes inside a <div>
</div>
block with Javascript.
Solution :
Use the document.getElementById("<replace with div id>").innerHTML
function.
For example :
<div id="content">
<h1>Original content</h1>
</div>
<script type="text/javascript">
document.getElementById("content").innerHTML='<h1>Modified content.</h1>';
</script>
See also : How to show different content from website server when AdBlock is detected?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+3.4k Android Studio : Indicate progression with ProgressBar example
+2.4k Fontello : How to load and use fonts?
+2k Golang : Find the shortest line of text example
+5.1k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+10.9k Golang : How to get hour, minute, second from time?
+10.7k Golang : Create and resolve(read) symbolic links
+13.4k Golang : Get time.Duration in year, month, week or day
+5k Golang : Sort and reverse sort a slice of runes
+8.5k Golang : How to get own program name during runtime ?
+13.1k SSL : How to check if current certificate is sha1 or sha2
+2.3k JQuery : Calling a function inside Jquery(document) block
+2.6k Golang : Missing Subversion command