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
+26.9k Golang : Find files by name - cross platform example
+10k Golang : How to profile or log time spend on execution?
+12.2k Golang : "https://" not allowed in import path
+14.9k Golang : Save(pipe) HTTP response into a file
+7.3k Golang : How to stop user from directly running an executable file?
+4.6k Golang : A program that contain another program and executes it during run-time
+5.5k Linux/Unix/PHP : Restart PHP-FPM
+11.9k Golang : md5 hash of a string
+6.1k Golang : How to get capacity of a slice or array?
+42.9k Golang : Get hardware information such as disk, memory and CPU usage
+12.7k Golang : Get terminal width and height example
+12.1k Golang : Get month name from date example