1

I want change background color without using click button

<script>  
    onclick.document.getElementById('myDiv').style.backgroundColor = 'red';   
</script>
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Iffy
  • 79
  • 1
  • 6
  • Hi and welcome to the SO community, you should add more description to your problem if you want to be helped. You should describe exactly what is your problem and how did you try to solve it. You can read this post: https://stackoverflow.com/help/how-to-ask – Hammerbot Mar 14 '18 at 10:57
  • @VishnuBhadoriya- seems like issue with click event handler – Pranay Rana Mar 14 '18 at 10:59

1 Answers1

0

you have to attach click event and then you can do it , there is nothing like this onclick.document.getElementById(

document.addEventListener("click", function(){
    document.getElementById("myDiv").style.backgroundColor = 'red';
});
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263