469,327 Members | 1,259 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

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:


Expand|Select|Wrap|Line Numbers
  1. kioskDemo.prototype.getImages = function() {
  2.     var source = '/global/mul/digital/kiosk/xml/'+this.page+'_'+this.country+'.xml';
  3.     HTTP.getXML(source, return_result);
  4.     function return_result(result) {
  5.         var items = result.getElementsByTagName('collection')[0];
  6.         for(x = 0; x<items.childNodes.length; x++) {
  7.             if(items.childNodes[x].tagName) {
  8.                 var images = items.childNodes[x];
  9.                 var nameTag = images.tagName.toString();
  10.                 var target = document.getElementById(nameTag);
  11.                 for(y = 0; y < images.childNodes.length; y++) {
  12.                     if(images.childNodes[y].tagName) { 
  13.                         var hlink = document.createElement('A');
  14.                         hlink.setAttribute('href','javascript: void(0);');
  15.                         hlink.setAttribute('class', 'k_button');
  16.                         // addEvent(hlink, 'click', kioskChangeFile);
  17.                         var image = document.createElement('img');
  18.                         image.src = images.childNodes[y].getAttribute('src');
  19.                         image.id = images.childNodes[y].getAttribute('name');
  20.                         target.appendChild(hlink); 
  21.                         hlink.appendChild(image);
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29.  
  30.  
  31. function launchKiosk() {
  32.     k.getImages();
  33.     var demo_container = document.getElementById('demo_container');
  34. //  A bunch of other unrelated code. . .  
  35.     var img_buttnz = document.getElementsByTagName('A');
  36.     alert(img_buttnz.length);
  37.     /* at this point, I found out that I cannot see these objects at all. */
  38. }
Oct 20 '08 #1
2 1888
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. target.appendChild(hlink);  
  2. hlink.appendChild(image); 
  3.  
You should really append image to hlink before you append hlink to target
Expand|Select|Wrap|Line Numbers
  1. hlink.appendChild(image); 
  2. target.appendChild(hlink);  
  3.  
Also give your hlink a name and id in the loop.
Oct 20 '08 #2
Also give your hlink a name and id in the loop.
iam_clint, thanks very much for the quick reply, that helped!
Oct 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Nicolas Van Lancker | last post: by
1 post views Thread by Shawn Modersohn | last post: by
2 posts views Thread by samuel.adam | last post: by
4 posts views Thread by Olorin | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.