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 Golang : Serving HTTP and Websocket from different ports in a program example
+16.6k Golang : Get all upper case or lower case characters from string example
+8.9k Golang : Compare files modify date example
+7.6k Golang : Progress bar with ∎ character
+7.8k Golang : Simple histogram example
+5.1k Golang : Missing Subversion command
+15.9k Golang : Check if IP address is version 4 or 6
+12.4k Golang : Query string with space symbol %20 in between
+5.7k Restart Apache or Nginx web server without password prompt
+22.9k Golang : Call function from another package
+13.4k Golang : Get URI segments by number and assign as variable example
+11.3k Golang : Sort and reverse sort a slice of bytes