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
+4.4k Javascript : How to show different content with noscript?
+8.3k Golang : Append and add item in slice
+18k Golang : Iterate linked list example
+8.5k Golang : Implementing class(object-oriented programming style)
+88.8k Golang : How to convert character to ASCII and back
+28.9k Get file path of temporary file in Go
+6.3k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+7.1k Nginx : Password protect a directory/folder
+7.6k Golang : How to detect if a sentence ends with a punctuation?
+14.7k Golang : Rename directory
+12.1k Golang : How to parse plain email text and process email header?
+20.6k Golang : Determine if directory is empty with os.File.Readdir() function