[Javascript] How to separate the href + V8 moment

Triche Osborne wdlists at triche-osborne.com
Thu Aug 11 12:51:14 CDT 2005


Scott Moore wrote:
> Thanks to everyone for their comments and suggestions. Here's where  I'm 
> at now, I've gone back to the original script and added Triche's  code 
> for denoting the first selected.
> 

Okay, the problem is that you've substituted the variable name 
"whichpic" for the variable name "obj," which gives any code using the 
"obj" name nothing to hang its hat on. Since your are passing the anchor 
object in your function call ("this" refers to the object itself, not 
the image in the href), it would be more descriptive to use "obj" for 
your passed variable. Here's the renamed version with the "selected" 
behavior intact, along with the shortened (V8) version of the code. I've 
tested it and everything works as you've described:

var Ary=new Array();
var firstSelected;

window.onload = function() {
firstSelected = document.getElementById('first');
firstSelected.className = "selected";
Ary[0] = firstSelected;
}

function showPic (obj) {

  if (!obj.set){
      obj.set=true;
      Ary[Ary.length]=obj;
     }

     for (i=0;i<Ary.length;i++){
      Ary[i].className='notselected';
     }

     if (document.getElementById) {
         document.getElementById('placeholder').src = obj.href;
         return false;
         } else {
         return true;
     }
}

Triche




More information about the Javascript mailing list