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
+8k Javascript : Put image into Chrome browser's console
+4.9k Fix Google Analytics Redundant Hostnames problem
+14.9k Golang : Normalize unicode strings for comparison purpose
+40.3k Golang : UDP client server read write example
+8.6k Golang : Generate Datamatrix barcode
+15.7k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+11.1k Nginx : TLS 1.2 support
+9.1k Golang : Inject/embed Javascript before sending out to browser example
+20.2k Golang : How to run your code only once with sync.Once object
+17.7k Golang : Clone with pointer and modify value
+14.1k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+16.6k Golang : Check if a string contains multiple sub-strings in []string?