[Javascript] How to separate the href

Scott Moore moore.scott at gmail.com
Wed Aug 10 19:20:28 CDT 2005


I'm using this script...

var Ary=new Array();
function showPic (obj,whichpic) {
     if (!obj.set){
      obj.set=true;
      Ary[Ary.length]=obj;
     }
     for (i=0;i<Ary.length;i++){
      Ary[i].className='notselected';
     }
     obj.className='selected';
         if (document.getElementById) {
                 document.getElementById('placeholder').src = whichpic;
         }
}

...which gives the CSS class of selected to a thumbnail when it's  
clicked and displays the larger version of the image where  
id=placeholder is defined, works  as intended when called using this  
link format.
<a onclick="showPic(this,'img01.jpg')"></a>

What I'm trying to figure out is how to modify the script to allow  
the href to be defined outside the onclick, like this:
<a onclick="showPic(this)" href="img01.jpg"></a>

I'm also trying to figure out how to have the first thumbnail link  
have the class=selected when the page first loads.

I have a feeling this is basic stuff for the experts, but I'm still  
learning and need some help.

Scott



More information about the Javascript mailing list