Multiple methods in a single event?
If upon clicking a button I wanted to have the text onpage turn blue, and the background turn red, what would I do?
Code:
<html>
<body>
Sample Text<br>
<button onclick="document.fgColor='blue';">Blue</button>
</body>
</html>
I can make the text turn blue... but simultaneously the page turn red?
Re: Multiple methods in a single event?
Seperate 2 statements or functions using semi-colon (;).
in you code, change the button's tag with this:
HTML Code:
<button onclick="document.fgColor='blue';document.bgColor='red';">Text 2 Blue, Back 2 Red</button>
Re: Multiple methods in a single event?
Don't use event handler attributes; keep scripting and structure separate.
The proper way to use events is to use addEventListener(), in proper browsers; attachEvent(), in IE.