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.3k Android Studio : How to detect camera, activate and capture example
+18.1k Golang : Get command line arguments
+6.8k Nginx : Password protect a directory/folder
+11k Golang : Web routing/multiplex example
+7.1k CloudFlare : Another way to get visitor's real IP address
+14.4k Golang : Rename directory
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+20.3k nginx: [emerg] unknown directive "passenger_enabled"
+36.3k Golang : Convert date or time stamp from string to time.Time type
+20.1k Golang : Determine if directory is empty with os.File.Readdir() function
+5.1k Golang : Convert lines of string into list for delete and insert operation