Forum Moderators: open
Having a bit of problem using .indexOf with a returned value of .getAttribute. The code seems to fail for some reason.
I've been looking at code all day and my eyes are tired.... Anyone cast any ideas why this isn't working?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">function getElementsByAttribute(attrTarget, attrValue) {
// Works out which DOM model is being used and sets 'container'
var container = container ¦¦ document;
// Places all tags witin the page into the 'allTags' as an array
var allTags = container.all ¦¦ container.getElementsByTagName("*");
// Cycle through the tags using a for loop
for (var i=0; i < allTags.length; i++) {
var holder = allTags[i].getAttribute(attrTarget);
if ((holder.indexOf(attrValue)) > -1){
alert ("WhooHOoooo");
}
}
}
function initPage() {
getElementsByAttribute("src", "images");
}
window.onload = initPage;
</script>
</head>
<body>
<img src="/images/navigation/foo.jpg" />
</body>
</html>
Thanks
Lee