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
+5.3k Swift : Get substring with rangeOfString() function example
+9.6k Golang : Detect number of faces or vehicles in a photo
+6.8k Golang : Use modern ciphers only in secure connection
+18k Golang : Display list of time zones with GMT
+20.2k PHP : Convert(cast) int to double/float
+29.7k Golang : How to verify uploaded file is image or allowed file types
+18.5k Golang : Read input from console line
+6.4k Golang : Output or print out JSON stream/encoded data
+10.5k Golang : Fix go.exe is not compatible with the version of Windows you're running
+3.2k Golang : Switch Redis database redis.NewClient
+9k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+8.9k Golang : How to get ECDSA curve and parameters data?