Simple DOM Exercise [Aug. 19, 2011, 10:42 a.m.]
SIMPLE DOM EXERCISE #1
Write a function called by clicking a button on a page to alert
- The number of links on the page
- The first and last of these links
( The answer is at http://jsbin.com/oweri3/edit )
SIMPLE DOM EXERCISE #2
//this function takes 3 arguments and
//must have an id already established
//on an element within your HTML
function insertion(el,id,text){
var parent = document.getElementById(id);
var newEl = document.createElement(el);
var txt = document.createTextNode(text);
var pasteEl = parent.appendChild(newEl);
pasteEl.appendChild(txt);
};
//the call to the function
insertion('p', 'top', 'inserted child text node');