Forum Moderators: open
<a id="A1">A1</a>
<a id="B2">B2</a>
<script type="text/javascript">
Event.observe(window, 'load', function() {
$('A1').observe('mouseover', function (e) {
$('B2').addClassName('shiny');
});
$('A1').observe('mouseout', function (e) {
$('B2').removeClassName('shiny');
});
});
</script>
<a id="A1">A1</a>
<a id="B2" onMouseOver="javascript:A1On();" onMouseOut="javascript:A1Off();>B2</a>
<script type="text/javascript">
function A1On() {
$("A1").removeClassName("remove");
$("A1").addClassName("add");
}
function A1off() {
$("A1").removeClassName("remove");
$("A1").addClassName("add");
}
</script>
1. They can be overwritten as there is only 1 event "handler", whereas you can have as many event "listeners" as you like:
<a id="A1" onclick="foo();">
<script type="text/javascript">
$('A1').onclick = function() {};
function foo() { alert('this will never happen');}
2. I don't like to muck up my HTML with behavioral stuff. When I need to modify some behavior, I need only look in the script file. Nice separation of content and behavior (unobtrusive JavaScript).
Also, if I *was* to use inline handlers, I would use all lower case (onmouseover instead of onMouseOver) in case I ever want to convert to XHTML (though that's not likely either). :) And lastly, I wouldn't use "javascript:" to prepend my event handlers as all browsers use JavaScript as the default scripting language anyway.