Find multiple elements by ID function getelements (/*ids...*/) {var elements = {};for (var i=0; i<arguments.length; i++) {var id = Arguments[i];var ELT =document.getelementbyid ("id"); if (ELT = = null) throw new Error ("No element with ID:" +id); elements[i ] = ELT;} return elements;} A parameter that returns the element's Textcontent or innertext//two parameters, sets the element's textcontent or innertextfunction textcontent with the value parameter's values (element, value) {var content = element.textcontent;if (value = = undefined) {if (content!==undefined) return content;else return element.in Nertext;} Else{if (content!== undefined) element.textcontent = Value;else Element.innertext = value;}} function textcontent () {var child, type, s= ""; for (child=e.firstchild; child!==null; child.nextsibling) {type = Child.nodetype;if (type = = 3| | type = = 4) {s + = Child.nodevalue;} else if (type = = 1) {s + = textcontent (child);}} return s;} function InsertAt (parent, child, N) {if (N < 0 | | n > parent.childNodes.length) throw new Error (' Invalid index '); else if (n ==parent.childnodes.length) Parent.appendchild (Child); Else Parent.insertbefore (Child, Parent.childnodes[n]);} Sorts the first <tbody> row according to the value of the nth cell in each row of the specified table//If there is a comparator function then uses it, otherwise the function sortrows is compared in alphabetical order (table, N, Comparator) {var tbody = Table.tbodies[0];var rows = Tbody.getelementsbytagname ("tr"); rows = Array.prototype.slice.call (rows, 0); Rows.sort (function (Row1, row2) {var cell1 = Row1.getelementsbytagname ("TD") [N];var cell2 = Row2.getelementsbytagname ("TD") [N];var val1 = Cell1.textcontent | | Cell1.innertext;var val2 = Cell2.textcontent | | Cell2.innertext;if (Comparator) Comparator (Val1, val2), if (Val1 < Val2) Return-1;else if (Val1 > Val2) return 1;else R Eturn 0;}); for (var i=0; i<rows.length; i++) Tbody.appendchild (Rows[i]);} Find tables <th> elements so that they can be clicked to click the caption to sort rows by that column Funciton makesortable (table) {var headers = document.getelementsbytagname ("th "); for (var i = 0; I
JavaScript authoritative Guide to learning notes