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
+16.8k Golang : Check if a directory exist or not
+8.5k Golang : Eroding and dilating image with OpenCV example
+22.3k Golang : Check if element exist in map
+19.9k Golang : Convert string slice to struct and access with reflect example
+5.3k Golang : Break string into a slice of characters example
+6k Golang : Get environment variable
+19.1k Golang : Pipe output from one os.Exec(shell command) to another command
+10k Google Maps URL parameters configuration
+5.7k Golang : Find the shortest line of text example
+3.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+5.6k Golang : Spell checking with ispell example