Matej Posted April 2, 2014 Share Posted April 2, 2014 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 More sharing options...
thescientist Posted April 2, 2014 Share Posted April 2, 2014 what's the problem? are you checking for errors? How is it not working? Link to comment Share on other sites More sharing options...
davej Posted April 3, 2014 Share Posted April 3, 2014 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> 1 Link to comment Share on other sites More sharing options...
Matej Posted April 3, 2014 Author Share Posted April 3, 2014 Thank you very much sir (it wasnt exactly what i wanted , but thank to you i figured out how to do it , so its even better ) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now