Jump to content

Changing color multiple times


Matej

Recommended Posts

Hello!

i'd like to ask about this script

 

function farba(newcol) {    this.style.color = newcol;}function ahoj() {    var sup = document.getElementById('aaa');    farba.call(sup,'blue'); if(sup.style.color == "blue"){sup.style.color="red"}else{sup.style.color="blue"}

 

what should i change there for it , to work please?:)

Link to comment
Share on other sites

Here's some demo code...

<!DOCTYPE html><html><head><meta charset="utf-8"><title>color</title><style>input{width:150px;height:50px;}</style><script>window.onerror = function(m, u, l){alert('Javascript Error: '+m+'nURL: '+u+'nLine Number: '+l);return true;}</script><script>window.onload = init;function init() {  document.getElementById('btn').onclick = ccc;}function ccc() {var c1 = this.style.color;if(c1 == "blue"){this.style.color="red";this.style.backgroundColor="blue";}else if(c1 == "red"){ this.style.color="green";this.style.backgroundColor="yellow";}else{this.style.color="blue";this.style.backgroundColor="red";}changebody(c1);}function changebody(pcolor){document.getElementById('b1').style.backgroundColor = pcolor;}</script></head><body id="b1"><input type="button" id="btn" value="Color Changer"/></body>    </html>
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...