<?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>Alexandru Dinulescu&#039;s Thoughts&#187; Javascript</title>
	<atom:link href="http://alexdweb.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexdweb.com/blog</link>
	<description>This blog is about everything/anything related to XHTML/CSS and of course my favourite js library, jQuery.</description>
	<lastBuildDate>Thu, 09 Dec 2010 12:04:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Javascript Max Random Numbers</title>
		<link>http://alexdweb.com/blog/2010/02/14/javascript-max-random-numbers/</link>
		<comments>http://alexdweb.com/blog/2010/02/14/javascript-max-random-numbers/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 21:37:31 +0000</pubDate>
		<dc:creator>Dinulescu Alexandru Adrian</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Javascript comparing numbers]]></category>

		<guid isPermaLink="false">http://alexdweb.com/blog/?p=307</guid>
		<description><![CDATA[Greetings This is another short and sweet posts, basically it involves using the Math. function to do some nifty tricks Lets say that you want to get a random number between 1 and 10 and you dont know how. Well the answer is quite easy and it involves combining 2 Math. functions. Math.floor&#40;&#41; and Math.random&#40;&#41;. [...]]]></description>
			<content:encoded><![CDATA[<p> Greetings </p>
<p> This is another short and sweet posts, basically it involves using the <code class="codecolorer javascript default"><span class="javascript">Math.</span></code> function to do some nifty tricks </p>
<p> Lets say that you want to get a random number between 1 and 10 and you dont know how. Well the answer is quite easy and it involves combining 2 <code class="codecolorer javascript default"><span class="javascript">Math.</span></code> functions. <code class="codecolorer javascript default"><span class="javascript">Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> and <code class="codecolorer javascript default"><span class="javascript">Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.</span></code> </p>
<h3> Math.random()</h3>
<p> This function takes a random number between 0 and 1 </p>
<h3> Math.floor()</h3>
<p> This function rounds a number down to it&#8217;s smaller number, for example. 4.4 would become 4, 4.6 would become 4 as well, -4.1 would become -5 as well as -4.6 would become -5 as well. </p>
<p><span id="more-307"></span></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #006600; font-style: italic;">// random number between 0 and 1 //</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div class='alpha'&gt; &lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.alpha&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// random number between 0 and 10 //</span><br />
<span style="color: #006600; font-style: italic;">// the * 11 part is the max number you can roll, you put 11 because 0.9 x 11 is less than 11 so it will be </span><br />
<span style="color: #006600; font-style: italic;">// rounded down to 10,</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div class='alpha'&gt; &lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.alpha&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// however you can get also a 0 number because 0.0(something) will be rounded to 0</span><br />
<span style="color: #006600; font-style: italic;">// in order to prevent that we add a +1 like this. this means that you will have numbers between 1 and 11 </span><br />
<span style="color: #006600; font-style: italic;">// so we have to make it * 10 instead of * 11</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div class='alpha'&gt; &lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.alpha&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://alexdweb.com/blog/2010/02/14/javascript-max-random-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MenuMatic BUG</title>
		<link>http://alexdweb.com/blog/2010/02/04/menumatic-bug/</link>
		<comments>http://alexdweb.com/blog/2010/02/04/menumatic-bug/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 20:35:03 +0000</pubDate>
		<dc:creator>Dinulescu Alexandru Adrian</dc:creator>
				<category><![CDATA[IE6 Bugs]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[IE Bugs]]></category>
		<category><![CDATA[menuMatic]]></category>
		<category><![CDATA[mooTOOLs]]></category>

		<guid isPermaLink="false">http://alexdweb.com/blog/?p=295</guid>
		<description><![CDATA[Hello This issue only happens with menuMatic and with vertical set menus. Basically in all IE browsers the sub-nav-menu didnt show up correctly. And another thing, when you have link tags inside li tags, you need to float the li tags in IE else you get a hidden spacer there (vertical lists only). and the [...]]]></description>
			<content:encoded><![CDATA[<p> Hello </p>
<p> This issue only happens with menuMatic and with vertical set menus. Basically in all IE browsers the sub-nav-menu didnt show up correctly. </p>
<p> And another thing, when you have link tags inside li tags, you need to float the li tags in IE else you get a hidden spacer there (vertical lists only). and the menu looks very odd. This is old IE6 issue, seems like both IE7 and only IE8 fixed it. Fuck that shit. </p>
<p><span id="more-295"></span></p>
<p> When in doubt, float it then clear it. This triggers hasLayout behavior and stuff gets fixed by itself. With that issue done i had another issue when the menu looked out of place. In order to fix that you need to open the menuMatic source file and look for fixHasLayoutBug: false, and change it to true. </p>
<p> On the developers site it works with it set to false, i really have absolutely no ideea why it gets triggered in my projects (2 out of 2 projects) and not there and to be honest i really cant be arsed to look into it. The CSS on both sites regarding to the menu matic is quite identical. I would have switched to something based on jQuery but unfortunately there isnt anything like that currently on the market., or from what i could find. Going with the noConlict() thing really annoys the hell out of me </p>
<p> In sum if it looks borked in IE then a) float the links b) float the li tags and c) set fixhaslayoutbug: true, in the menuMatic.js file. And if you still have issues in IE8 because thats where I had the main issues, then you need to do the following. Look where your vertical navigation menu is placed and make a new CSS and load it only for IE8. in that css go to  #subMenusContainer and at the top: property modify it so it looks just right. If needed you can also play with the .smOW class at the margin property in the same CSS below are a few images with the before and after </p>
<p> In my example I set the #subMenusContainer top: property to 222px and the .smOW margin-left to about 20ish px </p>
<div id="attachment_298" class="wp-caption alignleft" style="width: 240px"><a href="http://alexdweb.com/blog/wp-content/uploads/2010/02/ie8Before.jpg"><img src="http://alexdweb.com/blog/wp-content/uploads/2010/02/ie8Before-230x299.jpg" alt="IE8 Before" title="ie8Before" width="230" height="299" class="size-medium wp-image-298" /></a><p class="wp-caption-text">IE8 Before</p></div>
<div id="attachment_296" class="wp-caption alignleft" style="width: 240px"><a href="http://alexdweb.com/blog/wp-content/uploads/2010/02/ie7BeforeHasLayout.jpg"><img src="http://alexdweb.com/blog/wp-content/uploads/2010/02/ie7BeforeHasLayout-230x300.jpg" alt="" title="ie7BeforeHasLayout" width="230" height="300" class="size-medium wp-image-296" /></a><p class="wp-caption-text">IE7 Before Has Layout</p></div>
]]></content:encoded>
			<wfw:commentRss>http://alexdweb.com/blog/2010/02/04/menumatic-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery 1.4 Annoying Bug</title>
		<link>http://alexdweb.com/blog/2010/01/25/jquery-1-4-annoying-bug/</link>
		<comments>http://alexdweb.com/blog/2010/01/25/jquery-1-4-annoying-bug/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 16:19:39 +0000</pubDate>
		<dc:creator>Dinulescu Alexandru Adrian</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[InanisMOD Theme]]></category>
		<category><![CDATA[jQuery 1.4]]></category>
		<category><![CDATA[jQuery Bugs]]></category>

		<guid isPermaLink="false">http://alexdweb.com/blog/?p=288</guid>
		<description><![CDATA[Hello This post is going to be short and sweet. Basically jQuery 1.4 launched a couple of days ago and i thought i&#8217;d move my blog from 1.3.2 to 1.4 and lo and behold JS Error. I was going like WTF, and after trying to debug it for like 15mins i come to the following [...]]]></description>
			<content:encoded><![CDATA[<p> Hello </p>
<p> This post is going to be short and sweet. Basically jQuery 1.4 launched a couple of days ago and i thought i&#8217;d move my blog from 1.3.2 to 1.4 and lo and behold JS Error. </p>
<p> I was going like WTF, and after trying to debug it for like 15mins i come to the following conclusion. From my own personal experience, in jQuery 1.3.2 when you wanted something to happen to an element you went like this. Since i use WordPress for as my blogging platform not everytime the .elementClass element was present.  </p>
<p><span id="more-288"></span></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.elementClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">doSomethingHere</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;i'm a jQuery nublet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p> The JQuery parsed the XHTML code and if it encountered the <code class="codecolorer html4strict default"><span class="html4strict">stuff.elementClass</span></code> item, then the script would run, else it will just return Null and be on it&#8217;s way to the next thing which in our case is an alert(). </p>
<p> Now in JQuery 1.4 something very odd happens, or well, at least it happened to me. Basically when i ran the same script but now with jQuery 1.4 it returned in the firebug js console <code class="codecolorer javascript default"><span class="javascript">$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">doSomethingHere</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">is</span> <span style="color: #003366; font-weight: bold;">null</span></span></code> and the entire chain blocked. Of course this is extremely bad because that condition was on line 5 of my blog. WHICH WAS NOT AWESOME. </p>
<p> Anyways in order to fix this sort of weird behavior pattern you first have to CHECK if the element exists on the current page, and then APPLY stuff to it. So our code transforms itself into something like this. </p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.elementClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #006600; font-style: italic;">/* this can also be written as $(el).length &gt;= 1 */</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">doSomethingHere</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;script ran&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;i'm a jQuery nublet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p> And in case you have more than 1 of the same element you can chain it using the <code class="codecolorer javascript default"><span class="javascript">.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> function and the code transform itself into this </p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.elementClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> thisEl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span>thisEl<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> thisEl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;$<span style="color: #009900;">&#40;</span>thisEl<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">doSomethingHere</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;i'm a Jquery nublet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p> Gotta love updating to a new version&#8230; jeez </p>
]]></content:encoded>
			<wfw:commentRss>http://alexdweb.com/blog/2010/01/25/jquery-1-4-annoying-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Comparing Numbers</title>
		<link>http://alexdweb.com/blog/2010/01/15/javascript-comparing-numbers/</link>
		<comments>http://alexdweb.com/blog/2010/01/15/javascript-comparing-numbers/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 22:23:53 +0000</pubDate>
		<dc:creator>Dinulescu Alexandru Adrian</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Javascript comparing numbers]]></category>

		<guid isPermaLink="false">http://alexdweb.com/blog/?p=283</guid>
		<description><![CDATA[Hello This post is a very straightforward one, basically it involves using javascript to calculate the lowest or highest number from either an array or from some definite variables. One of the very useful possibilities of this is calculating the height and width of more than 3 columns and equalizing everything to the highest. To [...]]]></description>
			<content:encoded><![CDATA[<p> Hello </p>
<p> This post is a very straightforward one, basically it involves using javascript to calculate the lowest or highest number from either an array or from some definite variables. </p>
<p> One of the very useful possibilities of this is calculating the height and width of more than 3 columns and equalizing everything to the highest. </p>
<p> To achieve this we can use the <code class="codecolorer javascript default"><span class="javascript">Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> property and the <code class="codecolorer javascript default"><span class="javascript">Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> property. </p>
<p><span id="more-283"></span></p>
<h3> The Math.max() Property </h3>
<p> This property compares all the numbers presented and extracts the highest one. It can either be used as a simple stand-alone property like this: </p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> var1 <span style="color: #339933;">=</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> var2 <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> var3 <span style="color: #339933;">=</span> <span style="color: #CC0000;">40</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> maximum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>var1<span style="color: #339933;">,</span> var2<span style="color: #339933;">,</span> var3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #006600; font-style: italic;">// or like this</span><br />
<span style="color: #003366; font-weight: bold;">var</span> maximum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span><span style="color: #CC0000;">30</span><span style="color: #339933;">,</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p> Or we can set up an array and use it a number array to feed numbers to it. Such an example would look like this, however i mention that i couldnt get this example to work. I learned Javascript by learning jQuery, not the other way around. </p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">max</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">max</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Math<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> max <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 6</span></div></div>
<h3> The Math.min() Property </h3>
<p> This property does exactly the opposite of what Math.max() does, as in extracting the lowest number from a set array. The code is almost identical but for keeps sake here it is </p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> var1 <span style="color: #339933;">=</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> var2 <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> var3 <span style="color: #339933;">=</span> <span style="color: #CC0000;">40</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #003366; font-weight: bold;">var</span> minimum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>var1<span style="color: #339933;">,</span> var2<span style="color: #339933;">,</span> var3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #006600; font-style: italic;">// or like this</span><br />
<span style="color: #003366; font-weight: bold;">var</span> minimum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span><span style="color: #CC0000;">30</span><span style="color: #339933;">,</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">min</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">min</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Math<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> min <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://alexdweb.com/blog/2010/01/15/javascript-comparing-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

