windandwaves wrote:
[...]
Now, of course (!), I have another problem, I need to also swap the onmouseover and onmouseout for the other <A HREFs> that share
the same onmouseover and onmouseout elements. I have written this function, but it does not seem to work (yet):
function findothers(ono1){
What is ono1?
Case 1: Is it a reference to an onmouseover event, like:
...
var ono1 = someElement.onmouseover;
findothers(ono1);
...
Case 2: Is a reference to an element that has an onmouseover:
var ono1 = document.getElementById('elementWithAnOnmouseover' );
findothers(ono1);
Case 3: It is the string name of an onmouseover that has been
defined elsewhere:
function aFunkyFunc(){
...
}
...
var ono1 = 'aFunkyFunc';
findothers(ono1);
...
var el;
var c;
el = document.all.tags("A");
You seem to like IE, but a more cross-browser way is:
if (document.getElementsByTagName) {
var el = document.getElementsByTagName('A');
} else if (document.all) {
var el = document.all.tags('A');
}
And you can declare the variables el & c and give them values
when you first use them. Sometimes in long scripts it's nice to
declare them all in one spot so you don't accidentally double-up
on names, but for short scripts, it's common to declare them and
give them values at the same time, right where you need them.
c = el.length
for(var i = 0; i < c; i++){
This will run a lot faster as:
for ( var c = el.length - 1; c >= 0; c-- ) {
var e = el(i);
var ono2 = e.onmouseover;
if (ono1 == ono2) {
Why bother with ono2? You only use it once, so don't bother to
create it (unless you have some other use for it not shown here).
Assuming case 1 above:
var e = el[c];
if ( ono1 == e.onmouseover ){
swap(e);
}
Assuming case 2 above:
var e = el[c];
if ( ono1.onmouseover == e.onmouseover ){
swap(e);
}
Assuming case 3 above:
I can't help, I don't know how to get the name of the function
attached to an onmouseover unless you use some IE only method
(innerText? adjacentHTML?). Maybe it can be done with regExp.
Mike?
All of the above is offered as a suggestion, untested of course.
e.onmouseover is actually the entire script, not just the name of
the function. Do alert(e.onmouseover) and you'll see what I
mean.
e.g.
<script type="text/javascript">
function hiNic(a){
alert(a.onmouseover);
}
</script>
<span onmouseover="hiNic(this)">blah blah blah</span>
Displays:
function onmouseover(event) {
hiNic(this);
}
--
Rob