Replacing HTML Text with Javascript
Hello, I needed the following code block to make a light and dark theme in a project, I wanted to share it with my fellow developers. I hope the code will be useful for you :)
<div id="divs" onclick="fun()">Light</div>
<script>
let div = document.getElementById("divs"),
open = true;
function fun(){
if (open) {
div.innerHTML = 'Light';
} else {
div.innerHTML = 'Dark';
}
open = !open
}
</script>
Comments
Popular Articles
Popular Tags
- #directive
- #Function
- #Json
- #Class
- #SASS
- #Form
- #Redirect
- #API
- #Special Characters
- #Special
- #Random
- #Generating
- #
- #Text
- #Ajax
- #URL
- #Encrypting
- #React
- #Show
- #timeAgo
- #PSR-4
- #Hide
- #DDOS Protection
- #DDOS
- #cURL
- #Logic For Displaying Posts
- #Error
- #Key
- #General Error
- #1364 Field
- #Abbreviation
- #Blade
- #Version
- #QR
- #QR Code Generating
- #Array
- #Arrays with Key Values to String Statement
- #Short Tag
- #Activate
- #Real Time
- #Socket.io
- #301
- #Custom Directives
- #Iframe Detection
- #Date
- #Characters
- #Insert
- #Autoloader
- #Composer
- #Reading
There are no comments, make the firs comment