|
-
Nov 24th, 2006, 02:49 PM
#1
Thread Starter
Hyperactive Member
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?
-
Nov 24th, 2006, 04:25 PM
#2
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>
-
Nov 27th, 2006, 01:50 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|