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
+13.3k Golang : Convert IP version 6 address to integer or decimal number
+18.9k Golang : Reset or rewind io.Reader or io.Writer
+18.6k Golang : Measure http.Get() execution time
+13.5k Golang : Parsing or breaking down URL
+26.7k Golang : Record voice(audio) from microphone to .WAV file
+6.7k Golang : Example of how to detect which type of script a word belongs to
+9.8k Golang : Replace a parameter's value inside a configuration file example
+17.7k Golang : Set, Get and List environment variables
+5.2k Linux/MacOSX : Search for files by filename and extension with find command
+8.6k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+11.8k Golang : Transform comma separated string to slice example
+18.8k Golang : Compare floating-point numbers