www.webdeveloper.com
Results 1 to 2 of 2

Thread: DOM Help

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    9

    DOM Help

    Hey, I want to have <img src="asdf.jpg" alt="asdf">, but I can't generate an alt tag for some odd reason. Here is my code which is fairly simple, but I just can't figure out why it won't display (wont even generate the tag). Code I'm having trouble with is in bold.

    function galleryWidget () {
    // Set variable to 0 and begin blog counting
    var image = 0;
    if (image < 3)
    var i = image;
    while (i < 3) {
    // Access standard entries
    project=xmlDoc.getElementsByTagName("project")[i];

    // Grab blog values
    description=project.getElementsByTagName("description")[0].childNodes[0].nodeValue;
    thumbnail=project.getElementsByTagName("thumbnail2")[0].childNodes[0].nodeValue;

    // Organize blog values
    descriptionDisplay="alt=" + description;
    thumbnailDisplay="<img src=" + thumbnail + descriptionDisplay + " />";


    // Display blog values
    document.write(thumbnailDisplay);
    i++;
    }
    }

  2. #2
    Join Date
    May 2009
    Posts
    150
    Are you putting the double quotes in the tags you're getting the values from? Without them you're generating:

    HTML Code:
    <img src=somefilealt=the alt thing />
    Note also the lack of a space, you'll likely want:

    PHP Code:
    // Grab blog values
    description=project.getElementsByTagName("description")[0].childNodes[0].nodeValue;
    thumbnail=project.getElementsByTagName("thumbnail2")[0].childNodes[0].nodeValue;

    // Organize blog values
    thumbnailDisplay='<img src="' thumbnail '" alt="' description '" />'
    Also, I'd suggest using standard insertion methods such as things like createElement, new Image, insertBefore etc.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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