...

View Full Version : trying to enumerate document-and-down by tag? class? anything?



subhailc
11-01-2004, 10:26 AM
hi. something like this works, or worked, at some point



function init()
{
var p=document.getElementsByTagName("input");
for (var i=0;i<p.length;i++){
p[i].onfocus = p[i].style.borderColor="black";
p[i].onblur = p[i].style.borderColor="white";
}
}


or is for..in meant to be used in these situations? i dunno i just want to be able to apply some behaviours to all of "x" whether that's all the children of a particular parent or all instances of a tag or class, that'll give me a jumping off point.

codegoboom
11-01-2004, 12:34 PM
function init()
{
var p = document.getElementsByTagName("input");
var i = p.length;
while(i--)
{
p[i].onfocus = function(){this.style.borderColor="black"};
p[i].onblur = function(){this.style.borderColor="white"};
}
}

That's one way.

Garadon
11-01-2004, 12:39 PM
same as codge just written differently

function init()
{
var p=document.getElementsByTagName("input");
for (var i=0;i<p.length;i++){
p[i].onfocus =new Function("this.style.borderColor='blue';");
p[i].onblur =new Function("this.style.borderColor='white';");
}
}

liorean
11-01-2004, 07:19 PM
Or, more efficiently:
function init(){
var
i=0,
coll=document.getElementsByTagName('input'),
elm;
while(elm=coll.item(i++)){
elm.onfocus=function(){this.style.borderColor='blue';};
elm.onblur=function(){this.style.borderColor='white';};
}
}

subhailc
11-04-2004, 07:23 AM
thanks.

as an aside: if anyone knows the semantics of for..in i'd be curious. i vaguely remember something like



var p = document.getElementById('somelayer');
for (i in p) {
someotherlayer.innerText += p[i];
}

ca_redwards
11-04-2004, 12:17 PM
thanks.

as an aside: if anyone knows the semantics of for..in i'd be curious. i vaguely remember something like



var p = document.getElementById('somelayer');
for (i in p) {
someotherlayer.innerText += p[i];
}


In your browser's address bar, type:


javascript:
(function(objName){obj=eval(objName);var r=[];for(var i in obj){r[r.length]=objName+'.'+i+' = '+obj[i];if(obj==obj[i])r[r.length-1]+=' ****';if(obj[i]==null)r[r.length-1]='\t'+r[r.length-1]}r.sort();alert(r.join('\n')+'\n\n**** refers to '+objName);})(prompt('Object:','this'));
void(0);/*property: Copyright (c) 2003-2004, by Rick Renfrow.*/


Supply the name of a DOM object and press enter. An alphabetized list of the object's properties is displayed.

Does this help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum