Adding &nbsp

So, here is the code that is stepping through XML data and creating  img src's with a href's. That's working fine now.
However , I can't figure out how to put "&nbsp" in between each image.

// get the href data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[1].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;

//create a node and set href  
var ref = document.createElement("a");
ref.setAttribute("href",tdata);
img.insertBefore(ref);

//get the image data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[0].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;
var TN_content="http://www.www.www" +tdata+"?OpenElement" ;

//Create img node and set image
var newref=document.createElement("img");
newref.setAttribute("src",TN_content);
newref.setAttribute("border",0);
ref.appendChild(newref);
questfarAsked:
Who is Participating?
 
mshogrenCommented:
To add spacing you should consider using the margin and padding CSS properties of the elements rather than using a character.

For instance add this line to the code which creates the link.

ref.setAttribute("style", "margin: 20px");
0
 
mshogrenCommented:
Try this:

// get the href data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[1].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;

//create a node and set href  
var ref = document.createElement("a");
ref.setAttribute("href",tdata);
img.insertBefore(ref);

var sp = document.createTextNode("            ");
img.insertBefore(sp);

//get the image data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[0].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;
var TN_content="http://www.www.www" +tdata+"?OpenElement" ;

//Create img node and set image
var newref=document.createElement("img");
newref.setAttribute("src",TN_content);
newref.setAttribute("border",0);
ref.appendChild(newref);
0
 
rdcproCommented:
If you actually want the non-breaking space character (so that line breaks don't occur on it), then you'll have to add the right character.  A space character isn't the same thing.  

var sp = document.createTextNode(" ");
img.insertBefore(sp);

The actual character code might be different, depending on the encoding.  For example:    in UTF-16 or 슠 in UTF-8


Regards,
Mike Sharp
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
questfarAuthor Commented:
Well neither worked exactly, although the space was closer. The space was added in between the images , although I could not get it to add a space before the each first image in each row, regardless of where I put the code. The character code, simply put the text (" ") instead of a space, but it did add the characters in front of each first image in each row.



0
 
rdcproCommented:
mshogren makes a good point here...

Mike  
0
 
questfarAuthor Commented:
of course, CSS takes care of the rest, thanks for pointing in the right direction


Orlando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.