appendChild objects not recognized?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • holisticnetworking
    New Member
    • Oct 2008
    • 13

    appendChild objects not recognized?

    I'm using the xmlHttpRequest object to gather images and place them on a page. Later in the script, I need to add a function to their onClick property so they can do the business I need them for. However, after having placed them on the page, I cannot then snatch them up again to add the onClick.

    I'll readily accept the premise that I'm doing something backwards, but because a) the function I want to add to the onClick property is a method of the kioskDemo prototype and b) I want to pass the 'this' object to the method to make it work, it seems to me that I would want to add the onClick method later in the program, rather than when I'm building it in the getImages method.

    Here's the relevant code:


    Code:
    kioskDemo.prototype.getImages = function() {
    	var source = '/global/mul/digital/kiosk/xml/'+this.page+'_'+this.country+'.xml';
    	HTTP.getXML(source, return_result);
    	function return_result(result) {
    		var items = result.getElementsByTagName('collection')[0];
    		for(x = 0; x<items.childNodes.length; x++) {
    			if(items.childNodes[x].tagName) {
    				var images = items.childNodes[x];
    				var nameTag = images.tagName.toString();
    				var target = document.getElementById(nameTag);
    				for(y = 0; y < images.childNodes.length; y++) {
    					if(images.childNodes[y].tagName) { 
    						var hlink = document.createElement('A');
    						hlink.setAttribute('href','javascript: void(0);');
    						hlink.setAttribute('class', 'k_button');
    						// addEvent(hlink, 'click', kioskChangeFile);
    						var image = document.createElement('img');
    						image.src = images.childNodes[y].getAttribute('src');
    						image.id = images.childNodes[y].getAttribute('name');
    						target.appendChild(hlink); 
    						hlink.appendChild(image);
    					}
    				}
    			}
    		}
    	}
    }
    
    
    
    function launchKiosk() {
    	k.getImages();
    	var demo_container = document.getElementById('demo_container');
    //  A bunch of other unrelated code. . .  
    	var img_buttnz = document.getElementsByTagName('A');
    	alert(img_buttnz.length);
    	/* at this point, I found out that I cannot see these objects at all. */
    }
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Code:
    target.appendChild(hlink);  
    hlink.appendChild(image);
    You should really append image to hlink before you append hlink to target
    Code:
    hlink.appendChild(image); 
    target.appendChild(hlink);
    Also give your hlink a name and id in the loop.

    Comment

    • holisticnetworking
      New Member
      • Oct 2008
      • 13

      #3
      Originally posted by iam_clint
      Also give your hlink a name and id in the loop.
      iam_clint, thanks very much for the quick reply, that helped!

      Comment

      Working...