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
+19.8k Swift : Convert (cast) Int to int32 or Uint32
+4.5k Chrome : How to block socketloop.com links in Google SERP?
+5.3k Python : Print unicode escape characters and string
+30.5k Golang : Interpolating or substituting variables in string examples
+7.7k Golang : Grayscale Image
+4.1k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+11.5k Golang : GTK Input dialog box examples
+11.9k Golang : md5 hash of a string
+36.1k Golang : Convert(cast) int64 to string
+7.7k Golang : Sort words with first uppercase letter
+8.4k Golang : Progress bar with ∎ character
+8.6k Golang : Find network service name from given port and protocol