JZeig
asked on
simple javascript
I working with a training course on Lynda.com and I didn't purchase the exercise files. I created a file with a basic button, but it doesn't seem to be executing. Basically, it's suppose to change the body color. I was viewing in G Chrome. The button appears on the browser, but won't execute code.
Any suggestions???
Hello.htm
Any suggestions???
Hello.htm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Instead of assigning the function reference to the onclick attribute
document.getElementById('c olor').onc lick = changeColor;
you pass that function reference to the addEventListener() function:
document.getElementById('c olor').add EventListe ner( "click", changeColor );
document.getElementById('c
you pass that function reference to the addEventListener() function:
document.getElementById('c
JavaScript generally runs inside of a web browser. Java typically runs as a standalone executable--though it does have to be run through the Java runtime. Both languages have object-orientation, but the do so in different manners. Java is based on classes; JavaScript is based on prototypes (don't ask me to explain what that is; one of the web-dev guys would do it more justice than I could). Both languages are effectively cross-platform, though each could have different host implementations among the various platforms. Both languages have garbage collection, but each implements it in different ways. Both languages have C-style syntax. Java is a statically-typed language whereas Javascript is dynamically-typed.
ASKER
@Chatal Thank you. I think the instructor called it "camel-case naming". Gotta look that up.
@zc2 Thank you as well. Now I'm just getting started, but I appreciate all help. I'm sure he'll get to that optional code later. But btw, in the case of this code, what would be the event handler. Is it the function or that name of the function?
@kaufmed NProblem & thanks for the info... Oh and what is the difference???