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
+7.4k Yum Error: no such table: packages
+9.3k Golang : How to use if, eq and print properly in html template
+13.8k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+10.4k Android Studio : Highlight ImageButton when pressed on example
+36.9k Golang : UDP client server read write example
+6.6k Golang : Append and add item in slice
+6.7k Android Studio : Indicate progression with ProgressBar example
+9.2k Golang : Bubble sort example
+10.1k Golang : Print UTF-8 fonts on image example
+6.5k Golang : Handle Palindrome string with case sensitivity and unicode
+28k Get client IP Address in Go
+23.7k Golang : Convert file content into array of bytes