This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

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

  1. The number of links on the page
  2. 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');