On Apr 27, 3:05 am, 0m4r <omar.adob...@g mail.comwrote:
Good Morning everybody
I'm gonna to be crazy about, maybe, a stupid Javascript problem.
What I would like to code is a javascript script to obtain something
like this:
<div>
<span>title: the title</span>
<br/>
<span>link: the link</span>
</div>
the script I'm using is reported below, but it seems to not work
because it don't give me the the two span elements on the same line
(and isn't what I want...)
That doesn't make sense. What will happen is that the two text nodes a
appended one after the other to the same span, since you only create
one. Your code then shuffles the span and br elements because you
only create one of each.
>
var br = document.create Element("br");
var span = document.create Element("span") ;
var div = document.create Element("div");
span.appendChil d(document.crea teTextNode("tit le: " + title))
That appends a text node to the span.
div.appendChild (br);
That appends the br to the div.
div.appendChild (span);
and the span after the br.
span.appendChil d(document.crea teTextNode("lin k: " +
link));
Now you append another text node to the span.
div.appendChild (br);
That moves the br to after the span.
div.appendChild (span);
That moves the span to after the br.
>
Where I'm wrong? Could anybody to help me?
If you want two spans, you have to create two spans. After adding the
first span to the div, make another, then append the second text node
to that. If you want more than one br, make more but I think you only
need one.
Don't forget feature detection:
var div = document.create Element("div");
var span = document.create Element("span") ;
span.appendChil d(document.crea teTextNode("tit le: " + title))
div.appendChild (span);
div.appendChild (document.creat eElement('br')) ;
// Make another span
span = document.create Element("span") ;
span.appendChil d(document.crea teTextNode("lin k: " + link));
div.appendChild (span);
--
Rob