p3x
06-14-2005, 10:22 PM
Hi!
I have a <ul> list with about 4 items in it (<li> tags all properly closed with </li>)
The list looks something like this:
<ul>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
</ul>
Now I want to add <li> items with DOM. I have to add 1 <li> tag and within that tag, I have to add 2 <a> tags...
I use something like this:
var liTag = document.createElement('li');
liTag.setAttribute('id', liId);
ulTag.appendChild(liTag);
var aTag = document.createElement('a');
aTag.setAttribute('href', 'test.php');
liTag.appendChild(aTag);
aTag.innerHTML = id;
var aaTag = document.createElement('a');
aaTag.setAttribute('href', 'test2.php');
liTag.appendChild(aaTag);
aaTag.innerHTML = ' test2';
But that doesn't seem to work properly,...it seems to underline both hyperlinks , and treat them as one...or something, not sure what is happening, but it is wrong. How could I do this properly?
I have a <ul> list with about 4 items in it (<li> tags all properly closed with </li>)
The list looks something like this:
<ul>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
<li><a href="test.php">test</a><a href="test2.php">test2</a></li>
</ul>
Now I want to add <li> items with DOM. I have to add 1 <li> tag and within that tag, I have to add 2 <a> tags...
I use something like this:
var liTag = document.createElement('li');
liTag.setAttribute('id', liId);
ulTag.appendChild(liTag);
var aTag = document.createElement('a');
aTag.setAttribute('href', 'test.php');
liTag.appendChild(aTag);
aTag.innerHTML = id;
var aaTag = document.createElement('a');
aaTag.setAttribute('href', 'test2.php');
liTag.appendChild(aaTag);
aaTag.innerHTML = ' test2';
But that doesn't seem to work properly,...it seems to underline both hyperlinks , and treat them as one...or something, not sure what is happening, but it is wrong. How could I do this properly?