<?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>snippet &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/snippet/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>es6 swap variables</title>
		<link>/2018/02/13/es6-swap-variables/</link>
		<comments>/2018/02/13/es6-swap-variables/#respond</comments>
		<pubDate>Tue, 13 Feb 2018 08:18:15 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[es6]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[swap]]></category>

		<guid isPermaLink="false">/?p=3666</guid>
		<description><![CDATA[<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/09/03/the-better-way-to-unset-variables-in-php/" rel="bookmark" title="The Better Way to Unset Variables in PHP">The Better Way to Unset Variables in PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><script src="https://gist.github.com/stoimen/e81f9fd9f16ccaddbade7b0bf826c379.js"></script></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/09/03/the-better-way-to-unset-variables-in-php/" rel="bookmark" title="The Better Way to Unset Variables in PHP">The Better Way to Unset Variables in PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2018/02/13/es6-swap-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Get the Selected Option Text</title>
		<link>/2010/06/22/jquery-get-the-selected-option-text/</link>
		<comments>/2010/06/22/jquery-get-the-selected-option-text/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 17:33:56 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[Technical communication]]></category>

		<guid isPermaLink="false">/?p=1660</guid>
		<description><![CDATA[What&#8217;s the Task? First of all let me explain what is the task. If there&#8217;s a select menu with several options, each of which are with a given value attribute, the task is to get the text into the option tag, and not that of the value attribute. In that scenario let&#8217;s assume that we &#8230; <a href="/2010/06/22/jquery-get-the-selected-option-text/" class="more-link">Continue reading <span class="screen-reader-text">jQuery: Get the Selected Option Text</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/09/27/jquery-setting-up-a-vector-path-fill-color/" rel="bookmark" title="jQuery: Setting Up a Vector Path Fill Color">jQuery: Setting Up a Vector Path Fill Color </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/16/jquery-tooltip-plugin/" rel="bookmark" title="jQuery tooltip plugin!">jQuery tooltip plugin! </a></li>
<li><a href="/2010/04/06/jquery-what-about-this-title/" rel="bookmark" title="jQuery: what about this.title?">jQuery: what about this.title? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>What&#8217;s the Task?</h2>
<p>First of all let me explain what is the task. If there&#8217;s a select menu with several options, each of which are with a given value attribute, the task is to get the text into the option tag, and not that of the value attribute.</p>
<p>In that scenario let&#8217;s assume that we have the following HTML:</p>
<pre lang="html4strict">
<select id="my-select">
    <option value="1">value 1</option>
    <option value="2">value 2</option>
</select>
</pre>
<p><a href="/wp-content/uploads/2010/06/Picture-1.png"><img src="/wp-content/uploads/2010/06/Picture-1.png" alt="select menu" title="Select Menu" width="181" height="95" class="alignleft size-full wp-image-1671" /></a><br />
Note that in the official jQuery doc page, the selector is described in the same context, but with a different markup:</p>
<pre lang="html4strict">
<select id="my-select">
    <option>value 1</option>
    <option>value 2</option>
</select>
</pre>
<p>than the jQuery snippet looks like that:</p>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select").change(function() {
        alert($(this).val());
    });
});
</pre>
<p>Here&#8217;s interesting to note that there&#8217;s no value attribute set to the options, thus the selection of an element is correct and the returned value is correct. The problem is that this code doesn&#8217;t work correctly once you&#8217;ve a different value attribute, from the value enclosed into the option tag. In our case we&#8217;ve the markup shown on the first code snippet and we&#8217;d like to get the &#8220;value 2&#8221; string instead of &#8220;2&#8221;.<br />
<a href="/wp-content/uploads/2010/06/Picture-2.png"><img src="/wp-content/uploads/2010/06/Picture-2.png" alt="" title="Alert screen" width="329" height="130" class="alignleft size-full wp-image-1672" srcset="/wp-content/uploads/2010/06/Picture-2.png 329w, /wp-content/uploads/2010/06/Picture-2-300x118.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></a></p>
<h2>Source Code</h2>
<pre lang="html4strict">
<select id="my-select">
    <option value="1">value 1</option>
    <option value="2">value 2</option>
</select>
</pre>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select").change(function() {
        alert($(this).val());
    });
});
</pre>
<h2>Solution</h2>
<p>Finally the solution, is pretty simple and clear, but this time is not to so &#8220;native&#8221; and it&#8217;s definitely something you couldn&#8217;t expect! The only thing you&#8217;ve to do is to change the selector!</p>
<pre lang="javascript">
$(document).ready(function() {
    $("#my-select).change(function() {
        alert($('#my-select option:selected').html());
    });
});
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/09/27/jquery-setting-up-a-vector-path-fill-color/" rel="bookmark" title="jQuery: Setting Up a Vector Path Fill Color">jQuery: Setting Up a Vector Path Fill Color </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/16/jquery-tooltip-plugin/" rel="bookmark" title="jQuery tooltip plugin!">jQuery tooltip plugin! </a></li>
<li><a href="/2010/04/06/jquery-what-about-this-title/" rel="bookmark" title="jQuery: what about this.title?">jQuery: what about this.title? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/22/jquery-get-the-selected-option-text/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Get the Server&#8217;s IP Address with PHP</title>
		<link>/2010/06/20/get-the-servers-ip-address-with-php/</link>
		<comments>/2010/06/20/get-the-servers-ip-address-with-php/#respond</comments>
		<pubDate>Sun, 20 Jun 2010 18:47:12 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">/?p=1633</guid>
		<description><![CDATA[If there&#8217;s a need to get the server&#8217;s IP address with PHP, the answer is simple: Actually that looks pretty much like the getting the user&#8217;s IP address:<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/05/10/phpini-for-two-web-servers/" rel="bookmark" title="php.ini for two web servers">php.ini for two web servers </a></li>
<li><a href="/2010/05/22/php-functions-realpath/" rel="bookmark" title="PHP Functions: realpath()">PHP Functions: realpath() </a></li>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
<li><a href="/2012/08/17/its-not-true-that-php-arrays-are-copied-by-value/" rel="bookmark" title="It&#8217;s Not True that PHP Arrays are Copied by Value">It&#8217;s Not True that PHP Arrays are Copied by Value </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>If there&#8217;s a need to get the server&#8217;s IP address with PHP, the answer is simple:</p>
<pre lang="php">
<?php echo $_SERVER['SERVER_ADDR'] ?>
</pre>
<p>Actually that looks pretty much like the getting the user&#8217;s IP address:</p>
<pre lang="php">
<?php echo $_SERVER['REMOTE_ADDR'] ?>
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/05/10/phpini-for-two-web-servers/" rel="bookmark" title="php.ini for two web servers">php.ini for two web servers </a></li>
<li><a href="/2010/05/22/php-functions-realpath/" rel="bookmark" title="PHP Functions: realpath()">PHP Functions: realpath() </a></li>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
<li><a href="/2012/08/17/its-not-true-that-php-arrays-are-copied-by-value/" rel="bookmark" title="It&#8217;s Not True that PHP Arrays are Copied by Value">It&#8217;s Not True that PHP Arrays are Copied by Value </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/20/get-the-servers-ip-address-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a List Tree with the Beauty of jQuery</title>
		<link>/2010/06/17/build-a-list-tree-with-the-beauty-of-jquery/</link>
		<comments>/2010/06/17/build-a-list-tree-with-the-beauty-of-jquery/#respond</comments>
		<pubDate>Thu, 17 Jun 2010 14:39:07 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/2010/06/17/build-a-list-tree-with-the-beauty-of-jquery/</guid>
		<description><![CDATA[This is nothing useful, but let me show the beauty of jQuery. This snippet just adds more and more nodes on a simple UL based tree. Here&#8217;s the HTML: Node 1 Node 2 Node 3 Node 4 And that&#8217;s the jQuery: var index = 5; $('li > a').live('click', function() { $(this).parent().append('Node ' + index + &#8230; <a href="/2010/06/17/build-a-list-tree-with-the-beauty-of-jquery/" class="more-link">Continue reading <span class="screen-reader-text">Build a List Tree with the Beauty of jQuery</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/17/clickoutside-jquery-plugin/" rel="bookmark" title="clickoutside jQuery plugin">clickoutside jQuery plugin </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2009/06/17/mouseclick-outside-a-dom-element/" rel="bookmark" title="mouseclick outside a DOM element">mouseclick outside a DOM element </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>This is nothing useful, but let me show the beauty of jQuery. This snippet just adds more and more nodes on a simple UL based tree.</p>
<p>Here&#8217;s the HTML:</p>
<pre lang="html4strict">
<ul>
    <li><a href="#">Node 1</a></li>
    <li><a href="#">Node 2</a></li>
    <li><a href="#">Node 3</a></li>
    <li><a href="#">Node 4</a></li>
</ul>
</pre>
<p>And that&#8217;s the jQuery:</p>
<pre lang="javascript">
var index = 5;
$('li > a').live('click', function() {
    $(this).parent().append('<ul><li><a href="#">Node ' + index + '</a></li></ul>');

    index++;

    return false;
});
</pre>
<p>And here&#8217;s the <a href="http://stoimen.com/projects/jquery.tree/" target="_blank">demo</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
<li><a href="/2010/02/17/clickoutside-jquery-plugin/" rel="bookmark" title="clickoutside jQuery plugin">clickoutside jQuery plugin </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2009/06/17/mouseclick-outside-a-dom-element/" rel="bookmark" title="mouseclick outside a DOM element">mouseclick outside a DOM element </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/17/build-a-list-tree-with-the-beauty-of-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Comparision Snippet</title>
		<link>/2010/03/21/javascript-comparision-snippet/</link>
		<comments>/2010/03/21/javascript-comparision-snippet/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 06:35:23 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">/?p=1371</guid>
		<description><![CDATA[== vs. === I know this is really for beginners, but have you ever asked yourself what are the differences between == and === when comparing in JavaScript, and when to use it? Here&#8217;s an example: var a = false; alert(a === 0); // prints false That&#8217;s false. Even when both the zero and the &#8230; <a href="/2010/03/21/javascript-comparision-snippet/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Comparision Snippet</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/10/21/does-javascript-undefined-equals-undefined/" rel="bookmark" title="Does JavaScript undefined Equals undefined?">Does JavaScript undefined Equals undefined? </a></li>
<li><a href="/2009/03/09/flex-javascript-communcation-example/" rel="bookmark" title="Flex Javascript communcation example">Flex Javascript communcation example </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>== vs. ===</h2>
<p>I know this is really for beginners, but have you ever asked yourself what are the differences between <strong>==</strong> and <strong>===</strong> when comparing in JavaScript, and when to use it? Here&#8217;s an example:</p>
<pre lang="javascript">var a = false;
alert(a === 0); // prints false</pre>
<p>That&#8217;s false. Even when both the zero and the variable are faulty the entire operation is false. Because the 0 is a number and the variable a is boolean, therefore their different types give us the answer. If there was a comparision only with == the result would be true:</p>
<pre lang="javascript">var a = false;
alert(a == 0); // prints true</pre>
<p>It&#8217;s good when you expect some variable to match certain type to compare with ===. So the correct code is:</p>
<pre lang="javascript">var a = false;
alert(a === false); // prints true</pre>
<p>Here the type of a compares with boolean. See the complete <a href="http://www.stoimen.com/projects/javascript.comparision/" target="_blank">demo</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/10/21/does-javascript-undefined-equals-undefined/" rel="bookmark" title="Does JavaScript undefined Equals undefined?">Does JavaScript undefined Equals undefined? </a></li>
<li><a href="/2009/03/09/flex-javascript-communcation-example/" rel="bookmark" title="Flex Javascript communcation example">Flex Javascript communcation example </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/21/javascript-comparision-snippet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery cssText Helps You Improve Browser Reflows</title>
		<link>/2010/03/17/jquery-csstext-helps-you-improve-browser-reflows/</link>
		<comments>/2010/03/17/jquery-csstext-helps-you-improve-browser-reflows/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 08:32:17 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[cssText]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[reflow]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">/?p=1343</guid>
		<description><![CDATA[cssText You know you can manage to redraw an element with single browser reflow. Instead of using .style.property &#8230; you can simply add all CSS properties you&#8217;d like to change with simply appending to style.cssText property. var csstxt = $('#selector').css('cssText') + ';top:100;left:100;border:1px solid red;color:#f00;'; $('#selector').css('cssText', csstxt); That code is a replacement for $('#selector').css({ left : &#8230; <a href="/2010/03/17/jquery-csstext-helps-you-improve-browser-reflows/" class="more-link">Continue reading <span class="screen-reader-text">jQuery cssText Helps You Improve Browser Reflows</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/12/23/csstext-and-how-it-can-be-very-very-useful/" rel="bookmark" title="cssText and how it can be very very useful">cssText and how it can be very very useful </a></li>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/" rel="bookmark" title="CSS Priority: The Difference Between a.my-class and .my-class">CSS Priority: The Difference Between a.my-class and .my-class </a></li>
<li><a href="/2009/03/19/jquery-ajax-script-call/" rel="bookmark" title="JQuery ajax script call">JQuery ajax script call </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>cssText</h2>
<p>You know you can manage to redraw an element with single browser <em>reflow</em>. Instead of using .style.property &#8230; you can simply add all CSS properties you&#8217;d like to change with simply appending to <em>style.cssText</em> property.</p>
<pre lang="javascript">var csstxt = $('#selector').css('cssText') + ';top:100;left:100;border:1px solid red;color:#f00;';
$('#selector').css('cssText', csstxt);</pre>
<p>That code is a replacement for</p>
<pre lang="javascript">$('#selector').css({
   left : '100px',
   top : '100px',
   border : '1px solid red',
   color : '#f00'
});</pre>
<p>enjoy!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/12/23/csstext-and-how-it-can-be-very-very-useful/" rel="bookmark" title="cssText and how it can be very very useful">cssText and how it can be very very useful </a></li>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/03/11/css-priority-the-difference-between-a-my-class-and-my-class/" rel="bookmark" title="CSS Priority: The Difference Between a.my-class and .my-class">CSS Priority: The Difference Between a.my-class and .my-class </a></li>
<li><a href="/2009/03/19/jquery-ajax-script-call/" rel="bookmark" title="JQuery ajax script call">JQuery ajax script call </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/17/jquery-csstext-helps-you-improve-browser-reflows/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
