samedi 27 juin 2020

my If Else statement isnt working in javascript [closed]

hi I am new here to ask a question, what my question is, is that my code javascript code isnt working, and I am quite sure that my error is because of my javascript's if else statement.

my code :

<!DOCTYPE html>
<html>
<head>
<title>practice</title>
</head>
<body>

<div id="mydiv"><p>Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem 
IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum</p></div>

<button onclick="myfunc()">use dark/white theme</button>
<script type="text/javascript">

function myfunc()
 {
if (document.getElementById('mydiv').style.background-color == 'white') 
    {
document.getElementById('mydiv').style.background-color = 'black'
    }
else {
document.getElementById('mydiv').style.background-color = 'white'   
}
}           
 </script>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire