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.8k Swift : Convert (cast) String to Double
+5.9k Golang : Get Alexa ranking data example
+8.8k Golang : Get current, epoch time and display by year, month and day
+6.1k Golang : How to stop user from directly running an executable file?
+9.7k Golang : Delay or limit HTTP requests example
+18k Golang : Measure http.Get() execution time
+25.3k PHP : Convert(cast) string to bigInt
+4.1k Python : Convert(cast) string to bytes example
+9.2k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+4.8k Javascript : How to replace HTML inside <div>?
+12.3k Golang : Query string with space symbol %20 in between
+31.6k Golang : Converting a negative number to positive number