What's the best way to add an <li> with a nested <a> tag to an exisiting <ul>?
More simply, I want to create a structure like this :
<li><a href='something'>Click</a></li> from the ground up, and insert it into the ul DOM
When I use my method, it works in opera, but not in safari or firefox, however it does not produce any javascript errors, it just doesn't work!
Sample code [I've tried several ways...here's one]
Code:
var newli = document.createElement('li');
var aHref = document.createElement('a');
aHref.href = 'www.google.com';
var text = document.createTextNode('hello' );
newli.appendChild(aHref);
var child = parent_node.firstChild;
parent_node.insertBefore(newli, child);
parent_node.firstChild.firstChild.appendChild(text);
Is there a specific order that I have to create and insert the nodes?
This 'works' as in it inserts a node, but it isn't linked as it should be.
I've also tried aHref.setAttribute('href', '#6') ... but doesn't seem to work either.