<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to getElementByClass in Javascript &#8211; The Code</title>
	<atom:link href="http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/</link>
	<description>Technology &#038; Business blog of YDS Web Solution</description>
	<lastBuildDate>Wed, 19 Oct 2011 23:11:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Frank</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-290003</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Sun, 04 Sep 2011 16:06:02 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-290003</guid>
		<description>For multiple class names try this instead:

if (allHTMLTags[i].className.match(/(^&#124; )theClass( &#124;$)/))

this means it starts with the class name, or there is a space before the class name, and it ends with the class name, or there is a space after the class name.</description>
		<content:encoded><![CDATA[<p>For multiple class names try this instead:</p>
<p>if (allHTMLTags[i].className.match(/(^| )theClass( |$)/))</p>
<p>this means it starts with the class name, or there is a space before the class name, and it ends with the class name, or there is a space after the class name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asad</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-283592</link>
		<dc:creator>Asad</dc:creator>
		<pubDate>Sat, 25 Jun 2011 06:41:41 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-283592</guid>
		<description>how about making ur life 100 times simpler by just using JQuery?</description>
		<content:encoded><![CDATA[<p>how about making ur life 100 times simpler by just using JQuery?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maryse</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-280887</link>
		<dc:creator>Maryse</dc:creator>
		<pubDate>Sat, 04 Jun 2011 12:49:44 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-280887</guid>
		<description>Thanks a lot for this script! 

For those having trouble to make it work, I suggest looking at these characters: &#039; and &quot; because sometimes they paste a little stylish and are not recognized as code.</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this script! </p>
<p>For those having trouble to make it work, I suggest looking at these characters: &#8216; and &#8221; because sometimes they paste a little stylish and are not recognized as code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tin</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-276309</link>
		<dc:creator>Tin</dc:creator>
		<pubDate>Mon, 25 Apr 2011 17:46:10 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-276309</guid>
		<description>Hi!

I&#039;m just a newbie in JS. Could you write a simple but real example to display how we can getElementByClass? I&#039;ve tried out for many times but failed.

My code:


    /* getElementByClass
    /**********************/

    var allHTMLTags = new Array();

    function getElementByClass(theClass) {
    //Create Array of All HTML Tags
    var allHTMLTags=document.getElementsByTagName(&quot;*&quot;);

    //Loop through all tags using a for loop
    for (i=0; i&lt;allHTMLTags.length; i++) {

    //Get all tags with the specified class name.
    if (allHTMLTags[i].className==theClass) {

    //Place any code you want to apply to all
    //pages with the class specified.
    //In this example is to &quot;display:none;&quot; them
    //Making them all dissapear on the page.
	
	document.className(&#039;whatever&#039;).style.color=&#039;red&#039;;
    

    }
    }
    }
	

        div

I want to have the div with class name &quot;whatever&quot; that its text &quot;div&quot; is to be changed to red in colour.

Could you show me how we can achieve it?
Thank you!</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I&#8217;m just a newbie in JS. Could you write a simple but real example to display how we can getElementByClass? I&#8217;ve tried out for many times but failed.</p>
<p>My code:</p>
<p>    /* getElementByClass<br />
    /**********************/</p>
<p>    var allHTMLTags = new Array();</p>
<p>    function getElementByClass(theClass) {<br />
    //Create Array of All HTML Tags<br />
    var allHTMLTags=document.getElementsByTagName(&#8220;*&#8221;);</p>
<p>    //Loop through all tags using a for loop<br />
    for (i=0; i&lt;allHTMLTags.length; i++) {</p>
<p>    //Get all tags with the specified class name.<br />
    if (allHTMLTags[i].className==theClass) {</p>
<p>    //Place any code you want to apply to all<br />
    //pages with the class specified.<br />
    //In this example is to &quot;display:none;&quot; them<br />
    //Making them all dissapear on the page.</p>
<p>	document.className(&#039;whatever&#039;).style.color=&#039;red&#039;;</p>
<p>    }<br />
    }<br />
    }</p>
<p>        div</p>
<p>I want to have the div with class name &#8220;whatever&#8221; that its text &#8220;div&#8221; is to be changed to red in colour.</p>
<p>Could you show me how we can achieve it?<br />
Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirill</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-274557</link>
		<dc:creator>Kirill</dc:creator>
		<pubDate>Sun, 20 Feb 2011 11:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-274557</guid>
		<description>Thanks, for good idea, as i understand function getElementByClass(&#039;theClass&#039;) must be called after the last culry brace?</description>
		<content:encoded><![CDATA[<p>Thanks, for good idea, as i understand function getElementByClass(&#8216;theClass&#8217;) must be called after the last culry brace?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kose</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-274053</link>
		<dc:creator>Kose</dc:creator>
		<pubDate>Sat, 05 Feb 2011 07:20:09 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-274053</guid>
		<description>Hi, 

I&#039;m trying to figure out how to change the background of multiple div&#039;s (of class &quot;blank&quot;) with a single link.

var allHTMLTags = new Array();

function changeDivBG(imgName) {
var allHTMLTags=document.getElementsByTagName(&quot;blank&quot;);
for (i=0; i&lt;allHTMLTags.length; i++) {
if (allHTMLTags[i].className==imgName) {
allHTMLTags[i].style.backgroundImage = &quot;url(&quot;+imgName+&quot;)&quot;;
}
}
}

on the site I have multiples of this div



and one of this:
&lt;a href=&quot;#&quot; rel=&quot;nofollow&quot;&gt;Happy&lt;/a&gt;

But it&#039;s not working. I would appreciate any help!

Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I&#8217;m trying to figure out how to change the background of multiple div&#8217;s (of class &#8220;blank&#8221;) with a single link.</p>
<p>var allHTMLTags = new Array();</p>
<p>function changeDivBG(imgName) {<br />
var allHTMLTags=document.getElementsByTagName(&#8220;blank&#8221;);<br />
for (i=0; i&lt;allHTMLTags.length; i++) {<br />
if (allHTMLTags[i].className==imgName) {<br />
allHTMLTags[i].style.backgroundImage = &quot;url(&quot;+imgName+&quot;)&quot;;<br />
}<br />
}<br />
}</p>
<p>on the site I have multiples of this div</p>
<p>and one of this:<br />
<a href="#" rel="nofollow">Happy</a></p>
<p>But it&#8217;s not working. I would appreciate any help!</p>
<p>Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-268042</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Fri, 03 Dec 2010 16:41:19 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-268042</guid>
		<description>I modified it so that you can specify the tag type and it will work similar to getElementsById, but it will return an array of items

/*  function name: getElementByClass
 *  purpose: gets all elements based off of a class
 *  input: String, String (optional)
 *  output: none
 */
function getElementsByClass(theClass, classType)
{
  //pulls the elements based off of their tag
  //if one is not specified, it will pull everything
  var allHTMLTags=document.getElementsByTagName((classType?classType:&#039;*&#039;));
  
  //temp array that is going to grab our elements
  var returnerArray = new Array();
  
  //go through the main array of elements
  for (var i=0; i&lt;allHTMLTags.length; i++) 
  {
    //if the element is within the class we want
    //we will add it to our array
    if (allHTMLTags[i].className==theClass) 
    {
      returnerArray.push(allHTMLTags[i]);
    }
  }

  //send the array back to the calling function
  return returnerArray;
}</description>
		<content:encoded><![CDATA[<p>I modified it so that you can specify the tag type and it will work similar to getElementsById, but it will return an array of items</p>
<p>/*  function name: getElementByClass<br />
 *  purpose: gets all elements based off of a class<br />
 *  input: String, String (optional)<br />
 *  output: none<br />
 */<br />
function getElementsByClass(theClass, classType)<br />
{<br />
  //pulls the elements based off of their tag<br />
  //if one is not specified, it will pull everything<br />
  var allHTMLTags=document.getElementsByTagName((classType?classType:&#8217;*'));</p>
<p>  //temp array that is going to grab our elements<br />
  var returnerArray = new Array();</p>
<p>  //go through the main array of elements<br />
  for (var i=0; i&lt;allHTMLTags.length; i++)<br />
  {<br />
    //if the element is within the class we want<br />
    //we will add it to our array<br />
    if (allHTMLTags[i].className==theClass)<br />
    {<br />
      returnerArray.push(allHTMLTags[i]);<br />
    }<br />
  }</p>
<p>  //send the array back to the calling function<br />
  return returnerArray;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilia</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-265354</link>
		<dc:creator>Ilia</dc:creator>
		<pubDate>Mon, 08 Nov 2010 19:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-265354</guid>
		<description>This is exactly what I needed. Tahnks!</description>
		<content:encoded><![CDATA[<p>This is exactly what I needed. Tahnks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jude</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-256219</link>
		<dc:creator>Jude</dc:creator>
		<pubDate>Thu, 22 Jul 2010 18:10:01 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-256219</guid>
		<description>This is a great little script, thanks so much for posting man!</description>
		<content:encoded><![CDATA[<p>This is a great little script, thanks so much for posting man!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sve</title>
		<link>http://www.actiononline.biz/web/code/how-to-getelementsbyclass-in-javascript-the-code/comment-page-1/#comment-254637</link>
		<dc:creator>sve</dc:creator>
		<pubDate>Sun, 13 Jun 2010 10:37:26 +0000</pubDate>
		<guid isPermaLink="false">http://webgasm.actiononline.biz/code/?p=349#comment-254637</guid>
		<description>I don&#039;t have a problim with this script John, it&#039;s working fine on FF and Chrome, i&#039;m using this 

window.onload = function() {

  var allATags = new Array();
  var allATags = document.getElementsByTagName(&#039;A&#039;);

  for (i=0; i &lt; allATags.length; i++) {
    if (allATags[i].className == &#039;noshow&#039;) {
      allATags[i].onclick = function(){ return false; };
    }
  }
}</description>
		<content:encoded><![CDATA[<p>I don&#8217;t have a problim with this script John, it&#8217;s working fine on FF and Chrome, i&#8217;m using this </p>
<p>window.onload = function() {</p>
<p>  var allATags = new Array();<br />
  var allATags = document.getElementsByTagName(&#8216;A&#8217;);</p>
<p>  for (i=0; i &lt; allATags.length; i++) {<br />
    if (allATags[i].className == &#039;noshow&#039;) {<br />
      allATags[i].onclick = function(){ return false; };<br />
    }<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

