Latest Lists

I am working an exercise out of an old book concerning Using Node Properties and need help please.?

1.Create a new JavaScript function named generateList in a new HTML document. ( The original document has three lists that contain “The Legislature”, “The House” and “The Senate”) using the <li> tag. 2.Create a new element node for the <li> tag by calling the createElement method. 3.Create a new text node containing the text “The Legislature” by calling the createTextNode method. 4.Attach the text node created in Step 3 to the element node created in Step2 by calling appendChild method. ( the above creates the first list item. Repeat the above to create the second and third list items) 5. Create a new element node for the <ul> tag by calling the createElement method. 6. Attach the 3 <li> element nodes to the <ul> element node. 7. Create a new <div> element node. 8. Set an id attribute and assign the value of “ulist” for the div element node by calling the setAttribute method. 9. Attach the <ul> element node created to the <div> node. 10. Attach the <div> node to the document body. 11. Invoke the function with the onLoad event handler in the <body> tag. The unordered list should be displayed. I can’t get it to work…Help!

Public Comments

  1. <html><head><script> function generateList() { li1 = document.createElement("li"); txt = document.createTextNode("The Legislature"); li1.appendChild(txt); li2 = document.createElement("li"); txt = document.createTextNode("The House"); li2.appendChild(txt); li3 = document.createElement("li"); txt = document.createTextNode("The Senate"); li3.appendChild(txt); ul = document.createElement("ul"); ul.appendChild(li1); ul.appendChild(li2); ul.appendChild(li3); div = document.createElement("div"); div.setAttribute("id", "ulist"); div.appendChild(ul); document.body.appendChild(div); </script></head> <body onload="generateList()"> </body> </html>
Powered by Yahoo! Answers