www.webdeveloper.com
Results 1 to 2 of 2

Thread: Script to manage different types of thumbnails

  1. #1
    Join Date
    Dec 2009
    Posts
    1

    Script to manage different types of thumbnails

    This Js is designed to help the user when choosing items in my personal portfolio.

    Whats seem to be wrong?
    Cheeck out the webpage on:
    http://www.lampe.se/new/index.html

    Code:
    window.onload = initiera;
    
    function initiera () {
    
    showCat();
    }
    
    function showCat () {
    	//FilterCategorier
    	//-- WEB
    	var catWebBtn = document.getElementById("webBtn")
    	//-- PRINT
    	var catPrintBtn = document.getElementById("printBtn");
    	//-- 3D
    	var cat3dBtn = document.getElementById("tredBtn");
    	
    
    	var catBtn = new Array();
    	catBtn[0] = catWebBtn;
    	catBtn[1] = catPrintBtn;
    	catBtn[2] = cat3dBtn;
    
    
    	for(var i = 0; i < catBtn.length; i++) {
    		catBtn[i].onclick = function () {
    			var catHit = this.getAttribute("id");
    			alert(catHit);
    			
    
    			var thumbName = "thumbShadow"
    			
    
    			var thumb = document.getElementsByTagName("div").className = thumbName;
    			alert(thumb.length); //Returns "11"? Should be "9".
    		
    			for (var j = 0; j < thumb.length; i++) {
    				var currThumb = thumb[j];
    				var currThumbTitle = currThumb.getAttribute("title");
    				
    				if(currThumbTitle != catHit) {
    					currThumbTitle.style.display = "none";
    				}
    			}		
    		}
    	}
    }
    Thanks!

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    This doesn't work:
    Code:
    var thumb = document.getElementsByTagName("div").className = thumbName;
    You're trying to find elements by className:
    Code:
    function findByClass(tagname, classname) {
    var aObj=document.getElementsByTagName(tagname);
    var i=aObj.length; 
    var list=[];
    while(i--) { 
        if(aObj[i].id.indexOf(classname)!=-1) {list.push(aObj[i]);}
        }
    return list.reverse();
    }
    getElementsByClassName does exist, but is not supported in IE
    Last edited by Fang; 12-16-2009 at 06:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles