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
+6.9k Golang : Null and nil value
+32.3k Golang : Regular Expression for alphanumeric and underscore
+6.2k Golang : Calculate diameter, circumference, area, sphere surface and volume
+30.1k Golang : How to redirect to new page with net/http?
+8.8k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+24.9k Golang : Storing cookies in http.CookieJar example
+13k Golang : Linear algebra and matrix calculation example
+22.6k Golang : Calculate time different
+14.5k Golang : How to check for empty array string or string?
+7.9k Golang : Metaprogramming example of wrapping a function
+12.3k Golang : Add ASCII art to command line application launching process
+16.1k Golang : Execute terminal command to remote machine example