Friday, January 9, 2009

Code to Identify an element on the basis of it's any dom attribute and index

use firebug to identify the attributes and their values



function getLocator(elementClassName,attributeName,attribtePtrn,elemIndex){

var allInputArray = new Array();
var requiredElement;
allInputArray=document.getElementsByTagName(elementClassName);
var i=0;
var index=0;
var requiredIndex=elemIndex;

var pattrn=new RegExp("^"+attribtePtrn+"$");

for(i=0; i
if (pattrn.test(allInputArray[i].getAttribute(attributeName))){
if (index==requiredIndex){
requiredElement=allInputArray[i];
break;}
index=index+1;
}

}

return requiredElement;
}

//function call
getLocator("input","id","[a-c]{1}al00_mc_Chec.*",16);

1 Comment:

Anonymous said...

Sega Genesis video games Archives - Visionl.cc
A guide on how to watch a Sega Genesis video game. Find the youtube playlist to mp3 best and newest Genesis video games, and other great deals. Find an adage for Sega Genesis