SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Modify this script

    Can someone please help me modify this script

    Code:
    startList = function() {
    	if (document.all&&document.getElementById) {
    		navRoot = document.getElementById("namedrop");
    		for (i=0; i<navRoot.childNodes.length; i++) {
    			node = navRoot.childNodes[i];
    			if (node.nodeName=="LI") {
    				node.onmouseover=function() {
    					this.className+=" over";
    				}
    				node.onmouseout=function() {
    					this.className=this.className.replace(" over", "");
    				}
    			}
    		}
    	}
    }
    window.onload=startList;
    So that instead of picking an element that has an ID="namedrop" it picks an element that has a class="namedrop"?
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following should work
    Code:
    var startList = function(){
    	if(!document.getElementsByClassName) return;
    	var navRoot = document.getElementsByClassName("namedrop");
    	for (i=0; i<navRoot.childNodes.length; i++) {
    		var node = navRoot.childNodes[i];
    		if (node.nodeName=="LI") {
    			node.onmouseover= function() {
    				this.className+=" over";
    			};
    			node.onmouseout=function() {
    				this.className=this.className.replace(" over", "");
    			};
    		};
    	};
    };
    
    document.getElementsByClassName = function(searchClass,tag,node){
    	var classElements = new Array();
    	if ( node == null )
    		node = document;
    	if ( tag == null )
    		tag = '*';
    	var els = node.getElementsByTagName(tag);
    	var elsLen = els.length;
    	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    	for (i = 0, j = 0; i < elsLen; i++) {
    		if ( pattern.test(els[i].className) ) {
    			classElements[j] = els[i];
    			j++;
    		};
    	};
    	return classElements;
    };
    
    window.onload = startList;

  3. #3
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'childNodes.length' is null or not an object
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry forgot about that, change to the following

    Code:
    function startList(){
    	if(!document.getElementsByClassName) return;
    	var navRoot = document.getElementsByClassName("namedrop");
    	for (i=0; i<navRoot.length; i++) {
    		var node = navRoot[i];
    		if (node.nodeName=="LI") {
    			node.onmouseover= function() {
    				this.className+=" over";
    			};
    			node.onmouseout=function() {
    				this.className=this.className.replace(" over", "");
    			};
    		};
    	};
    };


Bookmarks

Posting Permissions

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