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
+3.7k Linux : sudo yum updates not working
+9.4k Golang : Fix go.exe is not compatible with the version of Windows you're running
+12.5k Golang : How to check if a file is hidden?
+20.5k Golang : How to reverse slice or array elements order
+8.9k Golang : Random Rune generator
+16k Golang : Clone with pointer and modify value
+10.5k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+13.4k Golang : Rename directory
+7.3k Golang : Convert word to its plural form example
+10.6k Golang : Detect user location with HTML5 geo-location
+8.9k Golang : Use regular expression to get all upper case or lower case characters example
+21.9k Find and replace a character in a string in Go