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.4k Golang : Determine if time variables have same calendar day
+16.7k Golang : When to use init() function?
+19.2k Golang : How to run your code only once with sync.Once object
+40.3k Golang : How to count duplicate items in slice/array?
+10.6k Google Maps URL parameters configuration
+6.5k Golang : Fibonacci number generator examples
+7.8k Golang : Check if integer is power of four example
+29.8k Golang : Generate random string
+6.6k Golang : Squaring elements in array
+12.5k Golang : Convert(cast) uintptr to string example
+47.2k Golang : How to convert JSON string to map and slice