1

I want change background color without using click button

<script>  
    onclick.document.getElementById('myDiv').style.backgroundColor = 'red';   
</script>
2
  • 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: stackoverflow.com/help/how-to-ask Commented Mar 14, 2018 at 10:57
  • @VishnuBhadoriya- seems like issue with click event handler Commented Mar 14, 2018 at 10:59

1 Answer 1

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';
});
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Sir its working.
sorry i cant understand upvote?
i think so i can accept answer, i jst started stackoverflow also i'm javascript beginner.
now i know wat u says :) I did mate.
@Iffy - if you are beginner then you can go through this course : w3schools.com/jsreF/default.asp not in much detail
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.