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
+6.6k Golang : Command line ticker to show work in progress
+5.2k Golang : Dealing with backquote
+18.4k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+4.8k Fix yum-complete-transaction error
+8.4k Golang : Find correlation coefficient example
+17.7k Golang : convert int to string
+10.4k Golang : Generate DSA private, public key and PEM files example
+17.9k Golang : Get RGBA values of each image pixel
+8k Golang : How to use Gorilla webtoolkit context package properly
+4.8k List of Golang XML tutorials
+61.5k Golang : Convert HTTP Response body to string
+8.3k Golang : Scramble and unscramble text message by randomly replacing words