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
+12.4k Golang : Convert int(year) to time.Time type
+12.7k Golang : How to get a user home directory path?
+10.8k Golang : How to pipe input data to executing child process?
+10.1k Golang : Select region of interest with mouse click and crop from image
+15.1k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+6.2k Golang : When to use make or new?
+17.1k Golang : delete and modify XML file content
+19.3k Golang : Determine if directory is empty with os.File.Readdir() function
+22.6k Golang : Randomly pick an item from a slice/array example
+14k Golang : How to filter a map's elements for faster lookup
+4.9k Responsive Google Adsense
+12.1k Golang : Exit, terminating or aborting a program