JS: fast through a list
var i = list.length; for(i; i> 0; i--) { alert(i) }
DZone Snippets > nataliedowne > javascript
12309 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Natalie Downe http://natbat.co.uk/
var i = list.length; for(i; i> 0; i--) { alert(i) }
// relationship of object 1 to object 2 function objectPaternity(obj1, obj2) { // given an object this function returns 'child' if obj1 is a child of obj2 // and 'parent' if obj1 is a parent of obj2 - then 'no' if neither var relationship = 'no'; var currentElement = obj1; while((typeof currentElement.parentNode != 'undefined') && (currentElement != document.body)) { // first cycle through all the parent elements of object 1 to see if object 2 is one of them if(currentElement.parentNode == obj2) { relationship = 'child'; } // walk up the tree and try again currentElement = currentElement.parentNode; } // if object 1 is not a child of object 2 then we test the other way arround if(relationship == 'no') { currentElement = obj2; while((typeof currentElement.parentNode != 'undefined') && (currentElement != document.body)) { // now cycle through all the parent elements of object 2 to see if object 1 is one of them if(currentElement.parentNode == obj1) { relationship = 'parent'; } // walk up the tree and try again currentElement = currentElement.parentNode; } } return relationship; }
function isIE(versionNumber) { var detect = navigator.userAgent.toLowerCase(); if(!(navigator && navigator.userAgent && navigator.userAgent.toLowerCase)) { return false; } else { if(detect.indexOf('msie') + 1) { // browser is internet explorer var ver = function() { // http://msdn.microsoft.com/workshop/author/dhtml/overview/browserdetection.asp // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). var rv = -1; // Return value assumes failure if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); } } return rv; }; var valid = true; // if the version can be found and the version is less than our version number it is invalid if ((ver > -1) && (ver < versionNumber)) { valid = false; } return valid; } else { return false } } }