JS according to the class name to locate objects, getElementsByClassName

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <title>According to the class object search</title>
  <script type="text/javascript">
		function getElementsByClassName(a, b) {
			if (a.getElementsByClassName) {
				return a.getElementsByClassName(b);
			} else {
				return function c(m, k) {
					if (k == null) {
						k = document;
					var h = [], g = k.getElementsByTagName("INPUT"), d = g.length, l = new RegExp("(^|\\s)" + m + "(\\s|$)"), f, e;
					for (f = 0, e = 0; f <d; f++) {
						if (l.test(g[f].className)) {
							h[e] = g[f];
					return h;
				}(b, a);

		function view(){
			var v = getElementsByClassName(document,"a");

<div class="a" id=1  style="width:300px;height:300px;background:red;float:left">

<div class="a" id=2 style="width:300px;height:300px;background:green;float:left">

<div class="a" id=3 style="width:300px;height:300px;background:red;float:left">


<input type="button" value="See classname for a number of a" onclick="view()"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Leonard at December 19, 2013 - 5:32 AM