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
+21.5k Golang : Get ASCII code from a key press(cross-platform) example
+18.4k Golang : How to get time from unix nano example
+6.7k Golang : Grayscale Image
+6k Golang : Squaring elements in array
+31.2k Golang : Regular Expression for alphanumeric and underscore
+10.7k Golang : Clean formatting/indenting or pretty print JSON result
+10.5k CodeIgniter : Import Linkedin data
+26.6k Golang : Change a file last modified date and time
+7.3k Golang : Convert word to its plural form example
+20.8k Golang : Securing password with salt
+14.9k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+4.4k Golang : Frobnicate or tweaking a string example