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
+11.1k Golang : Forwarding a local port to a remote server example
+26.1k Golang : Record voice(audio) from microphone to .WAV file
+16.5k Golang : How to log each HTTP request to your web server?
+20.7k Golang : How to run Golang application such as web server in the background or as daemon?
+9.3k Golang : Allow Cross-Origin Resource Sharing request
+27.5k Golang : Saving(serializing) and reading file with GOB
+17.4k Golang : Check whether a network interface is up on your machine
+22.8k Golang : How to validate URL the right way
+14.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+22.4k Golang : Check if element exist in map
+4.7k Golang : Markov chains to predict probability of next state example
+3.9k Golang : Calculate a pip value and distance to target profit example