All pastes #1448586 Raw Edit

getElementsByRegexId

public javascript v1 · immutable
#1448586 ·published 2009-06-05 11:29 UTC
rendered paste body
<script type="text/javascript">	(function ()	{		var			t = document.getElementsByTagName;		// Test the abilities of		// getElementsByTagName		if (t('*').length)		{			// Correct support			document.getElementsByRegexId = function (r)			{				var					e = t('*'),					a = [],					l = 0,					i;				for (i in e)				{					if (e[i].id && e[i].id.match(r))					{						a[l++] = e[i];					}				}				return a;			}		}		else if (t = document.all)		{			// Old IEs			document.getElementsByRegexId = function (r)			{				var					a = [],					l = 0,					i;				for (i in t)				{					if (t[i].id && t[i].id.match(r))					{						a[l++] = t[i];					}				}				return a;			}		}		else		{			// Unsupported			document.getElementsByRegexId = function ()			{				// Avoid errors				return [];			}		}	})();</script>