Hello,

I have written a javascript function which is stored in a file named core.js and a html document, which is named index.html.

index.html:
HTML Code:
<html>
<head>
<title>title</title>
<script type="text/javascript" src="core.js">
</script>
</head>
<body>
<ul>
<li class="dataTable">li1</li>
<li>li2</li>
<li class="dataTable">li3</li>
<li>li2</li>									
</ul>
<ul>
<li class="dataTable">li1</li>
<li>li2</li>
<li>li3</li>
<li>li4</li>									
</ul>
<table>
<tr>
<td>td1</td>
<td class="dataTable">td2</td>
<td>td3</td>
<td>td4</td>								
</tr>
</table>
</body>
</html>
core.js:
Code:
var Core = {};
Core.getElementsByClass = function(theClass)
{
  var elementArray = [];

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }
  
  var matchedArray = [];
  var pattern = new RegExp("(^| )" + theClass + "( |$)");

  for (var i = 0; i < elementArray.length; i++)
  {
    if (pattern.test(elementArray[i].className))
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
};

var myElementArray = Core.getElementsByClass("dataTable");
document.write(myElementArray[0]);
I would like to know, why doesn't this code work:

Code:
var myElementArray = Core.getElementsByClass("dataTable");
document.write(myElementArray[0]);