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
+10.7k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+5.3k Golang : Calculate half life decay example
+12.5k Golang : Extract part of string with regular expression
+25.9k Golang : Daemonizing a simple web server process example
+5.5k Unix/Linux : How to archive and compress entire directory ?
+30k Golang : Get and Set User-Agent examples
+26.4k Golang : Calculate future date with time.Add() function
+10.3k Golang : How to profile or log time spend on execution?
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+5.9k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+7.7k Javascript : Push notifications to browser with Push.js
+10k Golang : Translate language with language package example