<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dev.enekoalonso.com &#187; dom</title>
	<atom:link href="http://dev.enekoalonso.com/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.enekoalonso.com</link>
	<description>having fun with code</description>
	<lastBuildDate>Wed, 12 Oct 2011 21:40:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Finding duplicate ID&#8217;s on an HTML page</title>
		<link>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/</link>
		<comments>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/#comments</comments>
		<pubDate>Fri, 06 May 2011 17:49:34 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[ids]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[page]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=687</guid>
		<description><![CDATA[Looks like sometimes we forgot element ID&#8217;s are meant to be unique on a HTML page. Here is a little bit of code I just wrote to find duplicate ID&#8217;s on a page (run the code on your browser&#8217;s javascript console): var idList = &#123;&#125;; var nodes = document.getElementsByClassName&#40;&#39;&#39;&#41;; for &#40;var i in nodes&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Looks like sometimes we forgot element ID&#8217;s are meant to be unique on a HTML page. Here is a little bit of code I just wrote to find duplicate ID&#8217;s on a page (run the code on your browser&#8217;s javascript console):</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> idList = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> nodes = document.<span class="me1">getElementsByClassName</span><span class="br0">&#40;</span><span class="st0">&#39;&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> nodes<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>isNaN<span class="br0">&#40;</span>i<span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span> = idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span>? idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span><span class="nu0">+1</span>:<span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> id <span class="kw1">in</span> idList<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>idList<span class="br0">&#91;</span>id<span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;Duplicate id: #&quot;</span> + id<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Have fun!</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>May 12, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/" title="Angry Birds as a Web App">Angry Birds as a Web App</a> (0)</li><li>May 14, 2010 -- <a href="http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/" title="Interesting JSON vulnerability (old stuff)">Interesting JSON vulnerability (old stuff)</a> (0)</li><li>April 14, 2010 -- <a href="http://dev.enekoalonso.com/2010/04/14/getting-unique-timestamps-in-javascript/" title="Getting unique timestamps in Javascript">Getting unique timestamps in Javascript</a> (0)</li><li>March 24, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/" title="Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates">Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting JSON vulnerability (old stuff)</title>
		<link>http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/</link>
		<comments>http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/#comments</comments>
		<pubDate>Fri, 14 May 2010 21:00:56 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[issue]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=532</guid>
		<description><![CDATA[Somebody at work passed this article about an interesting vulnerability in web APIs that use JSON. The exploit combines Cross Site Request Forgery (CSRF) with a JSON Array hack allowing an evil site to grab sensitive user data from an unsuspecting user. The hack involves redefining the Array constructor, which is totally legal in Javascript. http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx [...]]]></description>
			<content:encoded><![CDATA[<p>Somebody at work passed this article about an interesting vulnerability in web APIs that use JSON.</p>
<blockquote><p>The exploit combines <a title="Cross Site Request Forgery" href="http://www.codinghorror.com/blog/archives/001175.html">Cross Site Request Forgery</a> (CSRF) with a JSON Array hack allowing an evil site to grab sensitive user data from an unsuspecting user. The hack involves redefining the Array constructor, which is totally legal in Javascript.</p></blockquote>
<p><a href="http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx">http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx</a></p>
<p>I&#8217;ve found a while ago that you can put pretty much any URL on a script tag and the browser will download the content right away, whether it&#8217;s javascript or not, as long as the type attribute in the tag is set to &#8216;text/javascript&#8217;.  But although browsers download the URL content and place it inside the script tag, you can&#8217;t get to the content from Javascript (using innerHTML, for instance). Or can you? Apparently, Firebug can, at least on the HTML tab. I&#8217;m not sure if Firebug has direct access to the DOM, other than through Javascript, but I hope that is the case.</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li><li>August 12, 2010 -- <a href="http://dev.enekoalonso.com/2010/08/12/little-tricks-concatenating-arrays-in-javascript/" title="Little tricks: concatenating arrays in Javascript">Little tricks: concatenating arrays in Javascript</a> (4)</li><li>February 19, 2010 -- <a href="http://dev.enekoalonso.com/2010/02/19/having-fun-with-mooml-and-twitter/" title="Having fun with Mooml &#038; Twitter">Having fun with Mooml &#038; Twitter</a> (0)</li><li>October 12, 2011 -- <a href="http://dev.enekoalonso.com/2011/10/12/command-line-scripting-with-node-js/" title="Command line scripting with Node.js">Command line scripting with Node.js</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I never use $$ on my projects (and barely use $)</title>
		<link>http://dev.enekoalonso.com/2010/01/15/i-never-use-on-my-projects-and-barely-use/</link>
		<comments>http://dev.enekoalonso.com/2010/01/15/i-never-use-on-my-projects-and-barely-use/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 04:53:28 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[getElementById]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=400</guid>
		<description><![CDATA[On all the projects I&#8217;ve worked on, I always try to follow the MVC arquitectural pattern, separating the model from the view *and* creating a controller. It may be a simple controller in charge of a tab-set, or an accordion. Or it may be a full size controller in charge of the whole page structure, [...]]]></description>
			<content:encoded><![CDATA[<p>On all the projects I&#8217;ve worked on, I always try to follow the <a href="http://en.wikipedia.org/wiki/Model–view–controller">MVC arquitectural pattern</a>, separating the model from the view <b>*and*</b> creating a controller. It may be a simple controller in charge of a tab-set, or an accordion. Or it may be a full size controller in charge of the whole page structure, on sites that make an extensive use of javascript.</p>
<p>Either way, I always have a controller for a dynamic section of the page and the controller always works with the container of that section. If I need to reference any element inside the container I will use this.container.getElementById() or this.container.getElements(), which will do a search only on the child elements of the container and not on the whole dom tree of the page.</p>
<p>Yes, it is very usual to see nowadays code that alters the links of a page <img src="http://l.wordpress.com/latex.php?latex=%28%27a%27%29%2C%20images%20or%20whatever.%20Every%20time%20we%20use%20%24%20or%20&#038;bg=0D324F&#038;fg=FFFFFF&#038;s=1" title="('a'), images or whatever. Every time we use $ or " style="vertical-align:-20%;" class="tex" alt="('a'), images or whatever. Every time we use $ or " /> we are searching the whole page. And coding like that is just a waste of resources.</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>December 18, 2008 -- <a href="http://dev.enekoalonso.com/2008/12/18/gravity-in-the-dom/" title="Gravity in the DOM ">Gravity in the DOM </a> (0)</li><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li><li>October 5, 2010 -- <a href="http://dev.enekoalonso.com/2010/10/05/javascript-console-in-the-terminal-command-line/" title="Javascript console in the terminal (command line)">Javascript console in the terminal (command line)</a> (1)</li><li>September 17, 2010 -- <a href="http://dev.enekoalonso.com/2010/09/17/mootools-core-for-server-and-mobile-development/" title="MooTools Core for Server and Mobile Development">MooTools Core for Server and Mobile Development</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2010/01/15/i-never-use-on-my-projects-and-barely-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gravity in the DOM</title>
		<link>http://dev.enekoalonso.com/2008/12/18/gravity-in-the-dom/</link>
		<comments>http://dev.enekoalonso.com/2008/12/18/gravity-in-the-dom/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 05:58:27 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[gravity]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[planet]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=166</guid>
		<description><![CDATA[A couple of days ago I created a demo to simulate planets on a 2D universe interacting each other like Gravity does in our lives. To compute the movements every planet had to be evaluated with each other on every step. Their position will be affected by the other planet position and in proportion to [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I created a demo to simulate planets on a 2D universe interacting each other like Gravity does in our lives. To compute the movements every planet had to be evaluated with each other on every step. Their position will be affected by the other planet position and in proportion to their respective mass. This means the speed of the planets doesn&#8217;t impact the attraction between them.</p>
<p>Today I decided to extend this demo a little bit more and I added a few things:</p>
<ul>
<li>Mass parameter to make mass independent from size.</li>
<li>Collision detector to merge planets when they meet each other with color effect.</li>
<li>Orbit trails</li>
</ul>
<p><a href="http://dev.enekoalonso.com/research/gravity-2.php"><img src="http://dev.enekoalonso.com/wp-content/uploads/2008/12/picture-143-415x300.png" alt="Gravity" title="Gravity" width="415" height="300" class="aligncenter size-medium wp-image-186" /></a></p>
<p>The result is very nice. The first option make it possible to create bigger planets with more mass but with a size that fits appropiately on the screen. The second option merged planets that collide, making it more like a real world. Finally, the orbit trails are just some sugar to see the trajectory followed by the plantes. To avoid the screen getting very messy, the trails clean up themselves after 25 seconds.</p>
<p>As you can see, the universe controller uses the <a href="http://dev.enekoalonso.com/2008/12/14/threads-in-javascript/">Thread class</a> I was talking about few days ago.</p>
<p>See both demos here:<br />
<a href="http://dev.enekoalonso.com/research/gravity.php">http://dev.enekoalonso.com/research/gravity.php</a><br />
<a href="http://dev.enekoalonso.com/research/gravity-2.php">http://dev.enekoalonso.com/research/gravity-2.php</a></p>
<p>PS: Please note there is no Canvas involved here. All objects on screen are DOM elements. Of course this is not the best way to do graphic animations on the web, but it is fun!</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>January 15, 2010 -- <a href="http://dev.enekoalonso.com/2010/01/15/i-never-use-on-my-projects-and-barely-use/" title="I never use $$ on my projects (and barely use $)">I never use $$ on my projects (and barely use $)</a> (0)</li><li>April 23, 2009 -- <a href="http://dev.enekoalonso.com/2009/04/23/sending-messages-between-javascript-objects/" title="Sending messages between Javascript objects">Sending messages between Javascript objects</a> (2)</li><li>December 14, 2008 -- <a href="http://dev.enekoalonso.com/2008/12/14/threads-in-javascript/" title="Threads in Javascript">Threads in Javascript</a> (1)</li><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2008/12/18/gravity-in-the-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very basic $ function to deal with element classes</title>
		<link>http://dev.enekoalonso.com/2008/12/04/very-basic-function-to-deal-with-element-classes/</link>
		<comments>http://dev.enekoalonso.com/2008/12/04/very-basic-function-to-deal-with-element-classes/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 05:36:37 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[element]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=78</guid>
		<description><![CDATA[When working with plain Javascript (no frameworks involved) some tasks can be harder to deal with than you expected. Here is who to solve one of this issues: dealing with multiple element classes.]]></description>
			<content:encoded><![CDATA[<p>If you are working with plain Javascript but still want to have some advantajes when dealing with element classes (element.className) you can write a small $ function like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> $ = <span class="kw2">function</span><span class="br0">&#40;</span>element<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">element</span> = element;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">getClasses</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">element</span>.<span class="me1">className</span>.<span class="me1">replace</span><span class="br0">&#40;</span><span class="re0">/\s+/</span>,<span class="st0">&#39; &#39;</span><span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">hasClass</span> = <span class="kw2">function</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw2">var</span> classes = <span class="kw1">this</span>.<span class="me1">getClasses</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="br0">&#40;</span>classes.<span class="me1">indexOf</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="nu0">-1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">addClass</span> = <span class="kw2">function</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw1">this</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">element</span>.<span class="me1">className</span> += <span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">element</span>.<span class="me1">className</span> ? <span class="st0">&#39; &#39;</span> :<span class="st0">&#39;&#39;</span><span class="br0">&#41;</span> + className;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">removeClass</span> = <span class="kw2">function</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">var</span> classes = <span class="kw1">this</span>.<span class="me1">getClasses</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;classes.<span class="me1">splice</span><span class="br0">&#40;</span>classes.<span class="me1">indexOf</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">this</span>.<span class="me1">element</span>.<span class="me1">className</span> = classes.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">return</span> <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Then, once you have a variable that contains a DOM element, you can use it like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span>mydomelement<span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">&#39;test&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span>mydomelement<span class="br0">&#41;</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">&#39;test&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&#39;element has class test&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; $<span class="br0">&#40;</span>mydomelement<span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">&#39;test&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> classes = $<span class="br0">&#40;</span>mydomelement<span class="br0">&#41;</span>.<span class="me1">getClasses</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This will let you work with elements that have multiple classes very easily.</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li><li>May 14, 2010 -- <a href="http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/" title="Interesting JSON vulnerability (old stuff)">Interesting JSON vulnerability (old stuff)</a> (0)</li><li>January 18, 2010 -- <a href="http://dev.enekoalonso.com/2010/01/18/finally-singletons-the-mootools-way/" title="Finally: Singletons, the Mootools way">Finally: Singletons, the Mootools way</a> (0)</li><li>January 17, 2010 -- <a href="http://dev.enekoalonso.com/2010/01/17/mooml-mootools-markup-language-intro/" title="Mooml: Mootools markup language (intro)">Mooml: Mootools markup language (intro)</a> (7)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2008/12/04/very-basic-function-to-deal-with-element-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

