Hi,
I want to get all elements on the page that have a certain string in their id, in this case “ac_history_3”.
I wrote a small function to do this, which gets all the elements on a page, and then compares them to a reg exp. This works and does what I want.
var myArray = document.getElementsByTagName ('*');
reg = "ac_history_3";
for (var i=myArray.length-1; i>=0; --i){
if (myArray[i].id.match(reg)){
alert("This is one of the elements you're looking for");
}
}
However the form I am working with is really long and I was wondering if there is a more efficient way to do this.
Something like: document.getElementByRegExp(“ac_history_3”);
I would be grateful if someone could tell me if there is a more efficient way to do this, or if the code above is the only way to do what I want.
Cheers.