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.6k Golang : How to check if a connection to database is still alive ?
+9.4k Golang : Create unique title slugs example
+12.2k Golang : calculate elapsed run time
+7.6k Android Studio : AlertDialog to get user attention example
+33k Golang : How to check if a date is within certain range?
+14.6k Golang : Execute function at intervals or after some delay
+5.8k Golang : Launching your executable inside a console under Linux
+14.2k Elastic Search : Mapping date format and sort by date
+20.8k Golang : Convert PNG transparent background image to JPG or JPEG image
+19.1k Golang : Check whether a network interface is up on your machine
+5.2k Javascript : Change page title to get viewer attention