<?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>JavaScript &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 10:35:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>JavaScript &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Do you know JavaScript? Are you sure? &#8211; Part Two</title>
		<link>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-two/</link>
					<comments>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-two/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 05 Mar 2017 09:21:30 +0000</pubDate>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JavaScript Basics]]></category>
		<category><![CDATA[JavaScript In Simple Language]]></category>
		<category><![CDATA[JavaScript Objects]]></category>
		<category><![CDATA[JavaScript Tutorial]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12082</guid>

					<description><![CDATA[Here we are going to a see an anothe article of the JavaScript series. In the first part, we have see some basics that you can start with. In this article, we will be discussing about the JavaScript object continuations and constructors etc. You can always see my other posts related to JavaScript here. We will be using Visual Studio for our development. If you are totally new to JavaScript, I strongly recommend you to read some basics here.I hope you will like this. Now let&#8217;s begin. Download source code Do you know JavaScript &#8211; Part Two Background This article [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Here we are going to a see an anothe article of the <a href="http://sibeeshpassion.com/category/JavaScript" target="_blank">JavaScript</a> series. In the <a href="http://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-1/" target="_blank">first part</a>, we have see some basics that you can start with. In this article, we will be discussing about the JavaScript object continuations and constructors etc.  You can always see my other posts related to JavaScript <a href="http://sibeeshpassion.com/category/JavaScript/" target="_blank">here</a>. We will be using <a href="http://sibeeshpassion.com/category/Visual-Studio/" target="_blank">Visual Studio</a> for our development. If you are totally new to JavaScript, I strongly recommend you to read some basics <a href="https://www.w3schools.com/js/" target="_blank">here</a>.I hope you will like this. Now let&#8217;s begin.</p>
<p><strong>Download source code</strong></p>
<li>
<a href="https://code.msdn.microsoft.com/Do-you-know-JavaScript-7506a9ec" target="_blank">Do you know JavaScript &#8211; Part Two</a>
</li>
<p><strong>Background</strong></p>
<p>This article is the second part of the series we have just started. If you haven&#8217;t read the first part yet, I stronglyh recommed you to read it <a href="http://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-1/" target="_blank">here</a>. </p>
<p><strong>Setting up the platform</strong></p>
<p>To get started with, here we are going to create an HTML file and JS file. </p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Do you know JavaScript? Are you sure? Part Two&lt;/title&gt;<br />
	&lt;meta charset=&quot;utf-8&quot; /&gt;<br />
    &lt;script src=&quot;JavaScript.js&quot;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><strong>Let&#8217;s begin our tutorial</strong></p>
<p>Now, please open your JavaScript file. We have some scripts to write.</p>
<p><strong>Constructor</strong></p>
<p>Have you ever created any constructor in JavaScript? Before going to create a one, it is beter to know what is the need for it. Let&#8217;s start with an example. Here I am going to create an object called bike. </p>
<p>[js]<br />
var bike = {<br />
    name: &quot;Thnuderbird&quot;,<br />
    color: &quot;Blue&quot;,<br />
    CC: &quot;350&quot;,<br />
    company: &quot;Royal Enfield&quot;,<br />
    tankCapacity: &quot;20&quot;,<br />
    abs: false,<br />
    showName: function () {<br />
        console.log(this.name);<br />
    }<br />
};<br />
[/js]</p>
<p>As you can read it, this object if holdong the common properties of my bike Royal Enfield Thunderbird. Now my question is this is the only bike you know? Absolutely no, right? So suppose you need to create an object for the brand new Bajaj Dominor? What will you do? Creating an another object? So what if you know more than 10 bikes. If your anser is creating 10 objects, that&#8217;s not fair at all. Instead, why don&#8217;t we share this common properties like name, color, cc ect&#8230;So we are going to create objects but we are not going to create the properties again. So let&#8217;s crete an object for Dominor. Before doing that, we need to create a bike construcor as follows.</p>
<p>[js]<br />
function Bike(name, color, cc, company, tankCapacity, abs) {<br />
    this.name = name;<br />
    this.color = color;<br />
    this.cc = cc;<br />
    this.company = company;<br />
    this.tankCapacity = tankCapacity;<br />
    this.abs = abs;<br />
    this.showName = function () {<br />
        console.log(&#8216;The name of the currnet bike is &#8216; + this.name);<br />
    }<br />
}<br />
[/js]</p>
<p>Now we can create object for Dominor as follows. Remember, when you write the word Bike, you can see that the intellisense is shown for you as follows.</p>
<div id="attachment_12083" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Constructor_intellisence-e1488699966952.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-12083" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Constructor_intellisence-e1488699966952.png" alt="Constructor_intellisence" width="634" height="305" class="size-full wp-image-12083" srcset="/wp-content/uploads/2017/03/Constructor_intellisence-e1488699966952.png 634w, /wp-content/uploads/2017/03/Constructor_intellisence-e1488699966952-300x144.png 300w, /wp-content/uploads/2017/03/Constructor_intellisence-e1488699966952-400x192.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12083" class="wp-caption-text">Constructor_intellisence</p></div>
<p>[js]<br />
var dominor = new Bike(&quot;Dominor&quot;, &quot;Black&quot;, &quot;Bajaj&quot;, &quot;20&quot;, true);<br />
dominor.showName();<br />
[/js]</p>
<p>Have you noticed that we have not created the function showName in the object dominor but in Bike, and we are still able to use that in the object dominor. And you can see an output as preceding in your browser console. </p>
<div id="attachment_12084" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Dominor_object_output.png"><img decoding="async" aria-describedby="caption-attachment-12084" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Dominor_object_output-e1488700077335.png" alt="Dominor_object_output" width="634" height="154" class="size-full wp-image-12084" srcset="/wp-content/uploads/2017/03/Dominor_object_output-e1488700077335.png 634w, /wp-content/uploads/2017/03/Dominor_object_output-e1488700077335-300x73.png 300w, /wp-content/uploads/2017/03/Dominor_object_output-e1488700077335-400x97.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12084" class="wp-caption-text">Dominor_object_output</p></div>
<p>And you can create an object for Royal Enfield Thunderbird as follows.</p>
<p>[js]<br />
var thunderbird = new Bike(&quot;Thunderbird&quot;, &quot;Marine&quot;, &quot;Royal Enfield&quot;, &quot;20&quot;, false);<br />
thunderbird.showName();<br />
[/js]</p>
<div id="attachment_12085" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Thunderbird_output-e1488700173116.png"><img decoding="async" aria-describedby="caption-attachment-12085" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Thunderbird_output-e1488700173116.png" alt="Thunderbird_output" width="634" height="171" class="size-full wp-image-12085" srcset="/wp-content/uploads/2017/03/Thunderbird_output-e1488700173116.png 634w, /wp-content/uploads/2017/03/Thunderbird_output-e1488700173116-300x81.png 300w, /wp-content/uploads/2017/03/Thunderbird_output-e1488700173116-400x108.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12085" class="wp-caption-text">Thunderbird_output</p></div>
<p><strong>Distinguish between own and inherited properties </strong></p>
<p>As the heading implies, we have two kind of properties, own and inherited. Let&#8217;s create an example to understand that.</p>
<p>[js]<br />
var thunderbird = new Bike(&quot;Thunderbird&quot;, &quot;Marine&quot;, &quot;Royal Enfield&quot;, &quot;20&quot;, false);<br />
thunderbird.isMine = true;</p>
<p>console.log(dominor.name + &quot; is yours or not? &quot;);<br />
console.log(&quot;isMine&quot; in dominor);<br />
console.log(thunderbird.name + &quot; is yours or not? &quot;);<br />
console.log(&quot;isMine&quot; in thunderbird);<br />
console.log(&quot;toString&quot; in dominor);<br />
console.log(&quot;toString&quot; in thunderbird);<br />
[/js]</p>
<p>Before runningit, Can you please guess what will be the output of the above coce block? If you find the answer, check whether your answer matches the below output.</p>
<div id="attachment_12087" style="width: 480px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Own_and_inherited_properties.png"><img decoding="async" aria-describedby="caption-attachment-12087" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Own_and_inherited_properties.png" alt="Own_and_inherited_properties" width="470" height="170" class="size-full wp-image-12087" srcset="/wp-content/uploads/2017/03/Own_and_inherited_properties.png 470w, /wp-content/uploads/2017/03/Own_and_inherited_properties-300x109.png 300w, /wp-content/uploads/2017/03/Own_and_inherited_properties-400x145.png 400w" sizes="(max-width: 470px) 100vw, 470px" /></a><p id="caption-attachment-12087" class="wp-caption-text">Own_and_inherited_properties</p></div>
<p>So isMine is the property that we jsut added to the object thunderbird, and the same is not available in the object dominor. That&#8217;s cool. But why the property toString is available in both object, we have not added that to our object right? This is because toString method is being inherited from the Object.prototype.</p>
<p><strong>Use of hasOwnProperty</strong></p>
<p>In the above code, we have just seen how to check any property is available in our object, but that doesn&#8217;t mean it is its own property right? To check that, we can use the hasOwnProperty. Let&#8217;s find out how to use it now.</p>
<p>[js]<br />
console.log(dominor.name + &quot; is yours or not? &quot;);<br />
console.log(dominor.hasOwnProperty(&quot;isMine&quot;));<br />
console.log(thunderbird.name + &quot; is yours or not? &quot;);<br />
console.log(thunderbird.hasOwnProperty(&quot;isMine&quot;));<br />
console.log(dominor.hasOwnProperty(&quot;toString&quot;));<br />
console.log(thunderbird.hasOwnProperty(&quot;toString&quot;));<br />
[/js]</p>
<p>Once again, please try to answer it your own, before you run it. </p>
<div id="attachment_12089" style="width: 367px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/hasOwnProperty_output.png"><img decoding="async" aria-describedby="caption-attachment-12089" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/hasOwnProperty_output.png" alt="hasOwnProperty_output" width="357" height="171" class="size-full wp-image-12089" srcset="/wp-content/uploads/2017/03/hasOwnProperty_output.png 357w, /wp-content/uploads/2017/03/hasOwnProperty_output-300x144.png 300w" sizes="(max-width: 357px) 100vw, 357px" /></a><p id="caption-attachment-12089" class="wp-caption-text">hasOwnProperty_output</p></div>
<p><strong>Looping through the object</strong></p>
<p>To loopthrough the each items in an object, you can use for loop as follow.</p>
<p>[js]<br />
for (var itm in thunderbird) {<br />
    console.log(itm);<br />
}<br />
[/js]</p>
<p>This is not the preffered way as we have not checked for hasOwnProperties, we are suppose to iterate only the properties which is its own. </p>
<div id="attachment_12090" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Looping_through_the_items_in_an_Object-e1488703343380.png"><img decoding="async" aria-describedby="caption-attachment-12090" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Looping_through_the_items_in_an_Object-e1488703343380.png" alt="Looping_through_the_items_in_an_Object" width="634" height="85" class="size-full wp-image-12090" srcset="/wp-content/uploads/2017/03/Looping_through_the_items_in_an_Object-e1488703343380.png 634w, /wp-content/uploads/2017/03/Looping_through_the_items_in_an_Object-e1488703343380-300x40.png 300w, /wp-content/uploads/2017/03/Looping_through_the_items_in_an_Object-e1488703343380-400x54.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12090" class="wp-caption-text">Looping_through_the_items_in_an_Object</p></div>
<p>So let&#8217;s rewrite the above code as follows.</p>
<p>[js]<br />
for (var itm in thunderbird) {<br />
    if (thunderbird.hasOwnProperty(itm)) {<br />
        console.log(itm + &quot;:&quot; + thunderbird[itm]);<br />
    }<br />
}<br />
[/js]</p>
<p>Here is the output.</p>
<div id="attachment_12091" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Iteration_with_hasOwnProperty-e1488703903787.png"><img decoding="async" aria-describedby="caption-attachment-12091" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Iteration_with_hasOwnProperty-e1488703903787.png" alt="Iteration_with_hasOwnProperty" width="634" height="227" class="size-full wp-image-12091" srcset="/wp-content/uploads/2017/03/Iteration_with_hasOwnProperty-e1488703903787.png 634w, /wp-content/uploads/2017/03/Iteration_with_hasOwnProperty-e1488703903787-300x107.png 300w, /wp-content/uploads/2017/03/Iteration_with_hasOwnProperty-e1488703903787-400x143.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12091" class="wp-caption-text">Iteration_with_hasOwnProperty</p></div>
<p>We have seen enough about objects right? Any idea how you can delete the property from an object?</p>
<p>[js]<br />
delete thunderbird.isMine;<br />
for (var itm in thunderbird) {<br />
    if (thunderbird.hasOwnProperty(itm)) {<br />
        console.log(itm + &quot;:&quot; + thunderbird[itm]);<br />
    }<br />
}<br />
[/js]</p>
<div id="attachment_12092" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/03/Delete_from_an_object-e1488704140711.png"><img decoding="async" aria-describedby="caption-attachment-12092" src="http://sibeeshpassion.com/wp-content/uploads/2017/03/Delete_from_an_object-e1488704140711.png" alt="Delete_from_an_object" width="634" height="216" class="size-full wp-image-12092" srcset="/wp-content/uploads/2017/03/Delete_from_an_object-e1488704140711.png 634w, /wp-content/uploads/2017/03/Delete_from_an_object-e1488704140711-300x102.png 300w, /wp-content/uploads/2017/03/Delete_from_an_object-e1488704140711-400x136.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12092" class="wp-caption-text">Delete_from_an_object</p></div>
<p>Now it is time for a question. What would be the output of the preceding code? </p>
<p>[js]<br />
console.log(delete thunderbird.toString);<br />
[/js]</p>
<p>It will return true, now run it again. What is the output? Again true? This is because of, toString is an inherited property so it won&#8217;t get deleted. So <em>thunderbird.toString</em> will always give you output.</p>
<p>That&#8217;s all for today. You can always download the source code attached to see the complete code and application. Happy coding!.</p>
<p><strong>References</strong></p>
<li><a href="https://www.w3schools.com/js/" target="_blank">JS</a></li>
<p><strong>See also</strong></p>
<li><a href="http://sibeeshpassion.com/category/JavaScript" target="_blank">Articles related to JavaScript</a></li>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-two/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Do you know JavaScript? Are you sure? &#8211; Part 1</title>
		<link>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-1/</link>
					<comments>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-1/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 28 Feb 2017 17:22:18 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JavaScript Basics]]></category>
		<category><![CDATA[JavaScript In Simple Language]]></category>
		<category><![CDATA[JavaScript Objects]]></category>
		<category><![CDATA[JavaScript Simple Demo]]></category>
		<category><![CDATA[JavaScript Tutorial]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12064</guid>

					<description><![CDATA[[toc] Introduction Here we are going to a series of articles related to JavaScript. As this is the first part of the series, here we are going to see some basics of JavaScript which you may forgot or you may not be aware of it. You can always see my other posts related to JavaScript here. We will be using Visual Studio for our development. Basically, JavaScript is a programming language of HTML and Web. Now a days we can create any kind of applications using JavaScript. If you are totally new to JavaScript, I strongly recommend you to read [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>Here we are going to a series of articles related to <a href="http://sibeeshpassion.com/category/JavaScript" target="_blank" rel="noopener">JavaScript</a>. As this is the first part of the series, here we are going to see some basics of JavaScript which you may forgot or you may not be aware of it. You can always see my other posts related to JavaScript <a href="http://sibeeshpassion.com/category/JavaScript/" target="_blank" rel="noopener">here</a>. We will be using <a href="http://sibeeshpassion.com/category/Visual-Studio/" target="_blank" rel="noopener">Visual Studio</a> for our development. Basically, JavaScript is a programming language of <a href="http://sibeeshpassion.com/category/html5/" target="_blank" rel="noopener">HTML</a> and Web. Now a days we can create any kind of applications using JavaScript. If you are totally new to JavaScript, I strongly recommend you to read some basics <a href="https://www.w3schools.com/js/" target="_blank" rel="noopener">here</a>. I hope you will like this. Now let&#8217;s begin.</p>
<h3><strong>Download source code</strong></h3>
<p>You can always download the source code from here <a href="https://code.msdn.microsoft.com/Do-you-know-JavaScript-ff7f3f98" target="_blank" rel="noopener">Do you know JavaScript &#8211; Part 1</a></p>
<h3><strong>Background</strong></h3>
<p>Recently I was assigned to a training task where I need to train one of my colleague who is a fresher and totally new to programming field. I had covered almost all the topics in my training and I am sharing few of them here. I hope you will like this.</p>
<h3>Using the code</h3>
<h4><strong>Create a HTML page</strong></h4>
<p>As we already said, JavaScript is a programming language of HTML and Web, we need a page to work with JavaScript. Let&#8217;s create it first.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;meta charset=&#8221;utf-8&#8243; /&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>Now create a JS file and include it in your page.</p>
<p>[js]<br />
&lt;script src=&#8221;JavaScript.js&#8221;&gt;&lt;/script&gt;<br />
[/js]</p>
<h4><strong>Let&#8217;s begin our tutorial</strong></h4>
<p>Any idea, what will be the output of the preceding lines of code.</p>
<p>[js]<br />
console.log(2 + 2);<br />
console.log(2 + &#8220;2&#8221;);<br />
console.log(2 + &#8220;2&#8221; + 2);<br />
console.log(2 + 2 + &#8220;2&#8221; + 2);<br />
console.log(2 + 2 + &#8220;2&#8221; + 2 + 2);<br />
console.log(2 + &#8220;2&#8221; + 2 + &#8220;2&#8221; + 2 + 2);<br />
console.log(&#8220;2&#8221; + 2 + &#8220;2&#8221; + 2 + 2 + 2 + 2);<br />
[/js]</p>
<p>Once after you run your application, press CTRL+SHIFT+J if you are opening your application in Google chrome or CTRL+SHIFT+K if it is Mozilla, or press F12 if in IE. This will open the browser console. Now check the output, is it the same as you thought?</p>
<div id="attachment_12065" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/02/Javascript_tutorial_output_1-e1488299369883.png"><img decoding="async" aria-describedby="caption-attachment-12065" class="size-full wp-image-12065" src="http://sibeeshpassion.com/wp-content/uploads/2017/02/Javascript_tutorial_output_1-e1488299369883.png" alt="Javascript_tutorial_output_1" width="634" height="197" srcset="/wp-content/uploads/2017/02/Javascript_tutorial_output_1-e1488299369883.png 634w, /wp-content/uploads/2017/02/Javascript_tutorial_output_1-e1488299369883-300x93.png 300w, /wp-content/uploads/2017/02/Javascript_tutorial_output_1-e1488299369883-400x124.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12065" class="wp-caption-text">Javascript_tutorial_output_1</p></div>
<p>If you noticed well, <em>console.log(2 + 2 + &#8220;2&#8221; + 2 + 2);</em> returned <em>4222</em>. First twos are added and when it comes to the third digit, the type of the result is being changed to string, so the string concatenation is happening. This is because of the dynamica nature of JavaScript.</p>
<p>So you can always add different types of values to the same variable in JavaScript. The preceding codes will always be working perfect.</p>
<p>[js]<br />
var a = 1;<br />
a = &#8220;Sibeesh&#8221;;<br />
[/js]</p>
<p>Now a simple test, what will be the output of the preceding code?</p>
<p>[js]<br />
var b;<br />
console.log(b);<br />
[/js]</p>
<p>Yes you are right it will return undefined as we have not assigned any values to the variable b. Have you ever checked the typeof an undefined variable?</p>
<p>[js]<br />
console.log(typeof(b));<br />
[/js]</p>
<p>The result will be undefined. Now what about the preceding codes?</p>
<p>[js]<br />
console.log(typeof(undefined));<br />
console.log(typeof(typeof(b)));<br />
console.log(typeof(String(b)));<br />
console.log(typeof({a:b}));<br />
console.log(typeof(null));<br />
[/js]</p>
<p>It can give you an output as below.</p>
<p>[js]<br />
undefined<br />
string<br />
string<br />
object<br />
object<br />
[/js]</p>
<p>Here one thing to be noted is, <em>typeof(typeof())</em> will always return string. And <em>{a:b}, null</em> is actually objects so the typeof will return the type as object. Let&#8217;s write a simple program now.</p>
<p>[js]<br />
var a=1;<br />
var b=a;<br />
a=2;</p>
<p>console.log(b);<br />
console.log(a);<br />
[/js]</p>
<p>See, how simple it was. Any idea what would be the output of that? If your answer is 1 &amp; 2, then you are right? Have you ever thought why is that? This is why the variable we just created are primitive types. In primitive data types the values are saved directly on the variable. If you are coming from the backgound of C#, you can understand the value typed variable.</p>
<p>Now we have one more data type which is referenced variable where values are stored as a reference not a direct values. An example for a referenced type variable is Object. Let&#8217;s go on to the next topic which is overview on JavaScript Objects, Do you know how to create an object?</p>
<p>[js]<br />
var myName = {firstName: &#8220;Sibeesh&#8221;, lastName: &#8220;Venu&#8221;};<br />
console.log(myName);<br />
console.log(JSON.stringify(myName));<br />
console.log(myName.firstName);<br />
console.log(myName.lastName);<br />
[/js]</p>
<p>Here myName is an object. You can always use JSON.stringify() to make your object to a string format and JSON.parse() to make your string to object. So the above code will give you an output as follows.</p>
<div id="attachment_12066" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/02/Javascript_tutorial_output_2-e1488300962889.png"><img decoding="async" aria-describedby="caption-attachment-12066" class="size-full wp-image-12066" src="http://sibeeshpassion.com/wp-content/uploads/2017/02/Javascript_tutorial_output_2-e1488300962889.png" alt="Javascript_tutorial_output_2" width="634" height="101" srcset="/wp-content/uploads/2017/02/Javascript_tutorial_output_2-e1488300962889.png 634w, /wp-content/uploads/2017/02/Javascript_tutorial_output_2-e1488300962889-300x48.png 300w, /wp-content/uploads/2017/02/Javascript_tutorial_output_2-e1488300962889-400x64.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12066" class="wp-caption-text">Javascript_tutorial_output_2</p></div>
<p>An object is a collection of key-value pairs, like we see in the above object, firstName is key and &#8220;Sibeesh&#8221; is value. How can we take any values from an object? We can always access a property from an object using dot(.) operator as follows.</p>
<p>[js]<br />
console.log(myName.firstName);<br />
console.log(myName.lastName);<br />
[/js]</p>
<p>And also using a bracket ([)</p>
<p>[js]<br />
console.log(myName[&#8220;firstName&#8221;]);<br />
console.log(myName[&#8220;lastName&#8221;]);<br />
[/js]</p>
<p>The above codes will give you an output as &#8220;Sibeesh&#8221; &#8220;Venu&#8221;, right? We just accesses a property from an object. Now we have given string value to our object as a key? Is there anyway we can give a key in number format? Let&#8217;s have a look.</p>
<p>[js]<br />
var myName = {1: &#8220;Sibeesh&#8221;, 2: &#8220;Venu&#8221;};<br />
[/js]</p>
<p>The question is, how can we access values of the keys 1 &amp; 2? Like below?</p>
<p>[js]<br />
console.log(myName.1);<br />
console.log(myName.2);<br />
[/js]</p>
<p>If you said &#8220;Yes&#8221;, you are wrong. If you try to accecc the values as above, This will throw an &#8220;Uncaught SyntaxError&#8221; error, so how can we access it?</p>
<p>[js]<br />
console.log(myName[&#8220;1&#8221;]);<br />
console.log(myName[&#8220;2&#8221;]);<br />
[/js]</p>
<p>So when the key value is a number, we must use [] for accessing the values. Now Lets go back to the previous object.</p>
<p>[js]<br />
var myName = {firstName: &#8220;Sibeesh&#8221;, lastName: &#8220;Venu&#8221;};<br />
var myNameCopy= myName;<br />
myName.firstName = &#8220;Sibi&#8221;;</p>
<p>console.log(myName.firstName);<br />
console.log(myNameCopy.firstName);<br />
[/js]</p>
<p>Any idea what will be the output of the above code? Have you just said Sibi Sibeesh? Oh, man. You got confused. The actual output is Sibi Sibi. As we said earlier, an object is an example of referenced type variable where the values are stored as a reference to it. So even if change the value of our first object, that will reflect is our second one too.</p>
<p>In the above examples we have created objects like below</p>
<p>[js]<br />
var myName = {firstName: &#8220;Sibeesh&#8221;, lastName: &#8220;Venu&#8221;};<br />
[/js]</p>
<p>This way of careating an object is called <em>Object literals</em>. Now the questuion is, is this the only way of creating the object? There is one more way, which is known as <em>Object Constructor</em>. Now we can create the same objects in Object constructor way.</p>
<p>[js]<br />
var myName = new Object();<br />
myName.firstName = &#8220;Sibeesh&#8221;<br />
myName.lastName = &#8220;Venu&#8221;;<br />
console.log(myName.firstName);<br />
console.log(myName.lastName);<br />
[/js]</p>
<p>Is there any rule that we can add only varibles to an object? Absolutely no, an object can hold a function too. Let&#8217;s create an object with a function inside.</p>
<p>[js]<br />
var myName = {<br />
firstName: &#8220;Sibeesh&#8221;,<br />
lastName: &#8220;Venu&#8221;,<br />
myFullName: function(){<br />
console.log(myName.firstName+&#8221; &#8220;+myName.lastName);<br />
}<br />
};<br />
[/js]</p>
<p>So the code <em>myName.myFullName();</em> will return my full name &#8220;Sibeesh Venu&#8221; as output. Right? So from the above code, we can create a functions in JavaScript as follows?</p>
<p>[js]<br />
var myFullName = function(firstName, lastName){<br />
return firstName + &#8221; &#8221; + lastName;<br />
}<br />
[/js]</p>
<p>If you call the above fucntion as preceding, you will get an output as &#8220;Sibeesh Venu&#8221;</p>
<p>[js]<br />
console.log(myFullName(&#8220;Sibeesh&#8221;,&#8221;Venu&#8221;));<br />
[/js]</p>
<p>The question is, what if we are passing only one values? Let&#8217;s try that out.</p>
<p>[js]<br />
console.log(myFullName(&#8220;Sibeesh&#8221;));<br />
[/js]</p>
<p>If you are working in any server side languages, this will actually give an error like &#8220;fucntion with one parameter couldn&#8217;t find&#8221;. But JavaScript is not like that, even if you are wrong, it will try to make you are right. So in this case, it actually treat the second parameter as undefined and give you an output as &#8220;Sibeesh undefined&#8221;.</p>
<p>That&#8217;s all for today. You can always download the source code attached to see the complete code and application. Happy coding!.</p>
<h3><strong>References</strong></h3>
<ul>
<li><a href="https://www.w3schools.com/js/" target="_blank" rel="noopener">JS</a></li>
</ul>
<h3><strong>See also</strong></h3>
<ul>
<li><a href="http://sibeeshpassion.com/category/JavaScript" target="_blank" rel="noopener">Articles related to JavaScript</a></li>
</ul>
<h3><strong>Conclusion</strong></h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3><strong>Your turn. What do you think?</strong></h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/do-you-know-javascript-are-you-sure-part-1/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Writing JavaScript Tests Using Jasmine Framework</title>
		<link>https://sibeeshpassion.com/writing-javascript-tests-using-jasmine-framework/</link>
					<comments>https://sibeeshpassion.com/writing-javascript-tests-using-jasmine-framework/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 10 Oct 2016 00:00:33 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Jasmine Framework]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Unit Testing With Jasmine]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11903</guid>

					<description><![CDATA[[toc] Introduction In this post we will see how we can write unit test cases in JavaScript. Here we are going to use a framework called Jasmine to write and test our unit test cases. Jasmine is a behavior driven development framework to test our JavaScript codes. The interesting things about Jasmine framework are, it doesn&#8217;t even require a DOM, independent on any framework, clean and easy. Here I will show you how we can create and run our JavaScript tests. I am going to use Visual Studio 2015 for the development. I hope you will like this article. Download [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In this post we will see how we can write unit test cases in <a href="http://sibeeshpassion.com/category/JavaScript/" target="_blank" rel="noopener">JavaScript</a>. Here we are going to use a framework called Jasmine to write and test our unit test cases. Jasmine is a behavior driven development framework to test our JavaScript codes. The interesting things about Jasmine framework are, it doesn&#8217;t even require a DOM, independent on any framework, clean and easy. Here I will show you how we can create and run our JavaScript tests. I am going to use <a href="http://sibeeshpassion.com/category/visual-studio/" target="_blank" rel="noopener">Visual Studio</a> 2015 for the development. I hope you will like this article.</p>
<h2><strong>Download source code</strong></h2>
<ul>
<li><a href="https://code.msdn.microsoft.com/Writing-JavaScript-Tests-2d1f99e9" target="_blank" rel="noopener">JavaScript Tests With Jasmine</a></li>
</ul>
<h2><strong>Background</strong></h2>
<p>As a developer, we all writes JavaScript codes for our client side developments. Am I right? It is more important to check whether the codes we have written works well. So for that we developer usually do unit testing, few developers are doing a manual testing to just check whether the functionality is working or not. But most of the MNC&#8217;s has set of rules to be followed while developing any functionalities, one of them is writing test cases, once the test cases passes, then only you will be allowed to move your codes to other environments. Here I will show you how we can write client side test cases with the help of a framework called Jasmine.</p>
<h2><strong>Setting up the project</strong></h2>
<p>To get started, please create an empty project in your Visual Studio.</p>
<div id="attachment_11904" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Empty_Project-e1475921231766.png"><img decoding="async" aria-describedby="caption-attachment-11904" class="size-full wp-image-11904" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Empty_Project-e1475921231766.png" alt="empty_project" width="650" height="507" srcset="/wp-content/uploads/2016/10/Empty_Project-e1475921231766.png 458w, /wp-content/uploads/2016/10/Empty_Project-e1475921231766-300x234.png 300w, /wp-content/uploads/2016/10/Empty_Project-e1475921231766-400x312.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11904" class="wp-caption-text">empty_project</p></div>
<p>Now, we will install <a href="http://sibeeshpassion.com/category/jquery/" target="_blank" rel="noopener">jQuery</a>, <a href="http://sibeeshpassion.com/category/jquery-ui/" target="_blank" rel="noopener">jQueryUI </a>from Nuget package manager.</p>
<div id="attachment_11905" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Nuget_Package_Manager.png"><img decoding="async" aria-describedby="caption-attachment-11905" class="size-large wp-image-11905" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Nuget_Package_Manager-1024x478.png" alt="nuget_package_manager" width="634" height="296" srcset="/wp-content/uploads/2016/10/Nuget_Package_Manager-1024x478.png 1024w, /wp-content/uploads/2016/10/Nuget_Package_Manager-300x140.png 300w, /wp-content/uploads/2016/10/Nuget_Package_Manager-768x358.png 768w, /wp-content/uploads/2016/10/Nuget_Package_Manager-400x187.png 400w, /wp-content/uploads/2016/10/Nuget_Package_Manager-1287x600.png 1287w, /wp-content/uploads/2016/10/Nuget_Package_Manager.png 1842w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11905" class="wp-caption-text">nuget_package_manager</p></div>
<p>We are all set to start our coding now.</p>
<h3><strong>Creating page and needed JS file</strong></h3>
<p>Next, we are going to create a page as preceding, with two text boxes and needed references.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Writing JavaScript test cases with Jasmine framework &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;meta charset=&#8221;utf-8&#8243; /&gt;<br />
&lt;link href=&#8221;Content/themes/base/jquery-ui.min.css&#8221; rel=&#8221;stylesheet&#8221; /&gt;<br />
&lt;link href=&#8221;Content/themes/base/base.css&#8221; rel=&#8221;stylesheet&#8221; /&gt;<br />
&lt;script src=&#8221;Scripts/jquery-3.1.1.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;Scripts/jquery-ui-1.12.1.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;Scripts/Index.js&#8221;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
Start Date: &lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; value=&#8221;&#8221; id=&#8221;dtStartDate&#8221; /&gt;<br />
End Date: &lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; value=&#8221;&#8221; id=&#8221;dtEndDate&#8221; /&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>Now we can start writing our JavaScript codes in the file <em>Index.js</em>. We will start with a document ready function as preceding.</p>
<p>[js]<br />
$(function () {<br />
$(&#8220;#dtStartDate&#8221;).datepicker();<br />
$(&#8220;#dtEndDate&#8221;).datepicker();<br />
$(&#8220;#dtEndDate&#8221;).on(&#8220;change leave&#8221;, function () {<br />
});<br />
});<br />
[/js]</p>
<p>Shall we create our validation functions? We will be creating a namespace indexPage and functions. You can see the validations below.</p>
<p>[js]<br />
var indexPage = {};<br />
indexPage.validationFunctions = (function () {<br />
return {<br />
getStartDateSelectedValue: function () {<br />
return $(&#8220;#dtStartDate&#8221;).val();<br />
},<br />
getEndDateSelectedValue: function () {<br />
return $(&#8220;#dtEndDate&#8221;).val();<br />
},<br />
isNullValue: function (selVal) {<br />
if (selVal.trim() == &#8220;&#8221;) {<br />
return true;<br />
}<br />
else {<br />
return false;<br />
}<br />
},<br />
isNullValueWithUIElements: function () {<br />
if (indexPage.validationFunctions.isNullValue(indexPage.validationFunctions.getStartDateSelectedValue())<br />
&amp;&amp; indexPage.validationFunctions.isNullValue(indexPage.validationFunctions.getEndDateSelectedValue())) {<br />
alert(&#8220;The values can&#8217;t be null!.&#8221;);<br />
}<br />
},<br />
isEndDateGreaterStart: function () {<br />
var startDate = new Date(indexPage.validationFunctions.getStartDateSelectedValue());<br />
var endDate = new Date(indexPage.validationFunctions.getEndDateSelectedValue());<br />
if (startDate &lt; endDate) {<br />
return true;<br />
}<br />
else {<br />
alert(&#8220;End date must be greater than start date!.&#8221;)<br />
return false;<br />
}<br />
}<br />
}<br />
}(jQuery));<br />
[/js]</p>
<p>Hope you are able t understand the codes written. We are wrote some validations like Null value check, end date greater than start date etc&#8230;</p>
<p>Now please run your application and check whether the validations are working fine.</p>
<div id="attachment_11906" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Null_validation_check.png"><img decoding="async" aria-describedby="caption-attachment-11906" class="size-large wp-image-11906" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Null_validation_check-1024x319.png" alt="null_validation_check" width="634" height="198" srcset="/wp-content/uploads/2016/10/Null_validation_check-1024x319.png 1024w, /wp-content/uploads/2016/10/Null_validation_check-300x93.png 300w, /wp-content/uploads/2016/10/Null_validation_check-768x239.png 768w, /wp-content/uploads/2016/10/Null_validation_check-400x124.png 400w, /wp-content/uploads/2016/10/Null_validation_check.png 1231w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11906" class="wp-caption-text">null_validation_check</p></div>
<div id="attachment_11907" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Date_validation_check.png"><img decoding="async" aria-describedby="caption-attachment-11907" class="size-large wp-image-11907" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Date_validation_check-1024x319.png" alt="date_validation_check" width="634" height="198" srcset="/wp-content/uploads/2016/10/Date_validation_check-1024x319.png 1024w, /wp-content/uploads/2016/10/Date_validation_check-300x93.png 300w, /wp-content/uploads/2016/10/Date_validation_check-768x239.png 768w, /wp-content/uploads/2016/10/Date_validation_check-400x125.png 400w, /wp-content/uploads/2016/10/Date_validation_check.png 1223w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11907" class="wp-caption-text">date_validation_check</p></div>
<p>Now, here comes the real part.</p>
<h3><strong>Setting up Jasmine Framework</strong></h3>
<p>To set Jasmine, we will add a new project to our solution.</p>
<div id="attachment_11908" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Add_new_project.png"><img decoding="async" aria-describedby="caption-attachment-11908" class="size-large wp-image-11908" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Add_new_project-1024x709.png" alt="add_new_project" width="634" height="439" srcset="/wp-content/uploads/2016/10/Add_new_project-1024x709.png 1024w, /wp-content/uploads/2016/10/Add_new_project-300x208.png 300w, /wp-content/uploads/2016/10/Add_new_project-768x532.png 768w, /wp-content/uploads/2016/10/Add_new_project-160x110.png 160w, /wp-content/uploads/2016/10/Add_new_project-400x277.png 400w, /wp-content/uploads/2016/10/Add_new_project-866x600.png 866w, /wp-content/uploads/2016/10/Add_new_project.png 1178w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11908" class="wp-caption-text">add_new_project</p></div>
<p>Now install Jasmine from Nuget Package manager.</p>
<div id="attachment_11909" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Jasmine_Nuget_Package.png"><img decoding="async" aria-describedby="caption-attachment-11909" class="size-large wp-image-11909" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Jasmine_Nuget_Package-1024x570.png" alt="jasmine_nuget_package" width="634" height="353" srcset="/wp-content/uploads/2016/10/Jasmine_Nuget_Package-1024x570.png 1024w, /wp-content/uploads/2016/10/Jasmine_Nuget_Package-300x167.png 300w, /wp-content/uploads/2016/10/Jasmine_Nuget_Package-768x428.png 768w, /wp-content/uploads/2016/10/Jasmine_Nuget_Package-400x223.png 400w, /wp-content/uploads/2016/10/Jasmine_Nuget_Package-1078x600.png 1078w, /wp-content/uploads/2016/10/Jasmine_Nuget_Package.png 1491w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11909" class="wp-caption-text">jasmine_nuget_package</p></div>
<p>Once you are done, the required files would be added to your project. We will be discussing about Jasmine once everything is set. So no worries.</p>
<p>Now please add a new HTML file on your Jasmine project, this is the page where we can see the test cases in actions, and add all the references as follows.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;</p>
<p>&lt;html lang=&#8221;en&#8221; xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
&lt;head&gt;<br />
&lt;meta charset=&#8221;utf-8&#8243; /&gt;<br />
&lt;title&gt;Jasmine Spec Runner &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;link href=&#8221;content/jasmine/jasmine.css&#8221; rel=&#8221;stylesheet&#8221; /&gt;<br />
&lt;script src=&#8221;http://localhost:12387/Scripts/jquery-3.1.1.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;http://localhost:12387/Scripts/jquery-ui-1.12.1.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;scripts/jasmine/jasmine.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;scripts/jasmine/jasmine-html.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;scripts/jasmine/console.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;scripts/jasmine/boot.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;scripts/indextests.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;http://localhost:12387/Scripts/Index.js&#8221;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<blockquote><p>Please do not forget to include the js files where we actually written the validations, jquery, jqueryui (if needed). Here indextests.js is the file where we are going to write the test cases.</p></blockquote>
<p>Normally this page is called as Spec Runner, Now you may be thinking what is a Spec? Before going further, there are some terms you must be aware of, there are listed below.</p>
<ul>
<li>Suites</li>
</ul>
<p>A suit is the starting point of a Jasmine test cases, it actually calls the global jasmine function <em>describe</em>. It can have two parameters, a string value which describes the suit, and a function which implements the suit.</p>
<ul>
<li>Spec</li>
</ul>
<p>Like suites, a spec starts with a string which can be the title of the suit and a function where we write the tests. A spec can contain one or more expectation that test the state of our code.</p>
<ul>
<li>Expectation</li>
</ul>
<p>Value of an expectation is either true or false, an expectation starts with the function <em>expect</em>. It takes a value and call the actual one.</p>
<p>You can always read more <a href="http://jasmine.github.io/2.0/introduction.html" target="_blank" rel="noopener">here</a>. Now please run your SpecRunner.html page. If everything is fine you can see a page as below.</p>
<div id="attachment_11910" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page.png"><img decoding="async" aria-describedby="caption-attachment-11910" class="size-large wp-image-11910" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page-1024x223.png" alt="jasmine_spec_runner_page" width="634" height="138" srcset="/wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page-1024x223.png 1024w, /wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page-300x65.png 300w, /wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page-768x167.png 768w, /wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page-400x87.png 400w, /wp-content/uploads/2016/10/Jasmine_Spec_Runner_Page.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11910" class="wp-caption-text">jasmine_spec_runner_page</p></div>
<p>So are you all set? Shall we go and write our test cases? Please go to your <em>IndexTest.js</em> file and create a suit and spec as preceding.</p>
<p>[js]<br />
describe(&#8220;Includes validations for index page&#8221;, function () {<br />
var indexPage;<br />
beforeEach(function () {<br />
indexPage = window.indexPage.validationFunctions;<br />
});</p>
<p>it(&#8220;Check for null values&#8221;, function () {<br />
// We are going to pass &#8220;&#8221; (null) value to the function<br />
var retVal = indexPage.isNullValue(&#8220;&#8221;);<br />
expect(retVal).toBeTruthy();<br />
});</p>
<p>});<br />
[/js]</p>
<p>Here the expectation is true and we give toBeTruthy(), now lets go and find whether the test is passed or not. Please run the SpecRunner.html page again.</p>
<div id="attachment_11911" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Test_Jasmine_Specs.png"><img decoding="async" aria-describedby="caption-attachment-11911" class="size-large wp-image-11911" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Test_Jasmine_Specs-1024x199.png" alt="test_jasmine_specs" width="634" height="123" srcset="/wp-content/uploads/2016/10/Test_Jasmine_Specs-1024x199.png 1024w, /wp-content/uploads/2016/10/Test_Jasmine_Specs-300x58.png 300w, /wp-content/uploads/2016/10/Test_Jasmine_Specs-768x149.png 768w, /wp-content/uploads/2016/10/Test_Jasmine_Specs-400x78.png 400w, /wp-content/uploads/2016/10/Test_Jasmine_Specs.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11911" class="wp-caption-text">test_jasmine_specs</p></div>
<p>Now we will write test case for our function <em>isEndDateGreaterStart</em>, if you have noticed the function <em>isEndDateGreaterStart</em>, you can see that there are dependencies (UI elements). Inside of the function, we are getting the values from the UI elements.</p>
<p>[js]<br />
var startDate = new Date(indexPage.validationFunctions.getStartDateSelectedValue());<br />
var endDate = new Date(indexPage.validationFunctions.getEndDateSelectedValue());<br />
[/js]</p>
<p>So in this case, we need to mock this values. It is known as &#8216;Spy&#8217; in Jasmine. We can use a function called <em>SpyOn</em> for this.</p>
<p>[js]<br />
it(&#8220;Spy call for datepicker date validation&#8221;, function () {<br />
//Start date as 2015-03-25<br />
spyOn(indexPage, &#8220;getStartDateSelectedValue&#8221;).and.returnValue(&#8220;2015-03-25&#8221;);<br />
//End date as 2015-03-24<br />
spyOn(indexPage, &#8220;getEndDateSelectedValue&#8221;).and.returnValue(&#8220;2015-03-24&#8221;);<br />
var retVal = indexPage.isEndDateGreaterStart();<br />
expect(retVal).toBeFalsy();<br />
});<br />
[/js]</p>
<p>Here we are giving start date as 2015-03-25 and end date as 2015-03-24 and we know 2015-03-25 &lt; 2015-03-24 is false, so here we are giving expectation as false (toBeFalsy()). Now you are getting an alert as follows right?</p>
<div id="attachment_11912" style="width: 776px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278.png"><img decoding="async" aria-describedby="caption-attachment-11912" class="size-full wp-image-11912" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278.png" alt="alert_in_spyon_jasmine" width="766" height="571" srcset="/wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278.png 478w, /wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278-300x224.png 300w, /wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278-650x485.png 650w, /wp-content/uploads/2016/10/Alert_in_SpyOn_Jasmine-e1475924905278-400x298.png 400w" sizes="(max-width: 766px) 100vw, 766px" /></a><p id="caption-attachment-11912" class="wp-caption-text">alert_in_spyon_jasmine</p></div>
<p>But in testing framework we don&#8217;t need any alerts right? To get rid of this, you must create a spy for window.alert function and add it to the <em>beforeEach</em> so that it can be used for each specs. You can do that as follows.</p>
<p>[js]<br />
window.alert = jasmine.createSpy(&#8220;alert&#8221;).and.callFake(function () { });<br />
[/js]</p>
<p>Once after you add this code, alert message won&#8217;t be thrown. Now please add an another spec with true values (Start date &#8211; 2015-03-25, End date &#8211; 2015-03-26), so that it will return true.</p>
<p>[js]<br />
it(&#8220;Spy call for datepicker date validation toBeTruthy&#8221;, function () {<br />
//Start date as 2015-03-25<br />
spyOn(indexPage, &#8220;getStartDateSelectedValue&#8221;).and.returnValue(&#8220;2015-03-25&#8221;);<br />
//End date as 2015-03-26<br />
spyOn(indexPage, &#8220;getEndDateSelectedValue&#8221;).and.returnValue(&#8220;2015-03-26&#8221;);<br />
var retVal = indexPage.isEndDateGreaterStart();<br />
expect(retVal).toBeTruthy();<br />
});<br />
[/js]</p>
<p>Now you can see all of your specs are passed.</p>
<div id="attachment_11913" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/10/Run_all_specs_in_Jasmine.png"><img decoding="async" aria-describedby="caption-attachment-11913" class="size-large wp-image-11913" src="http://sibeeshpassion.com/wp-content/uploads/2016/10/Run_all_specs_in_Jasmine-1024x217.png" alt="run_all_specs_in_jasmine" width="634" height="134" srcset="/wp-content/uploads/2016/10/Run_all_specs_in_Jasmine-1024x217.png 1024w, /wp-content/uploads/2016/10/Run_all_specs_in_Jasmine-300x64.png 300w, /wp-content/uploads/2016/10/Run_all_specs_in_Jasmine-768x163.png 768w, /wp-content/uploads/2016/10/Run_all_specs_in_Jasmine-400x85.png 400w, /wp-content/uploads/2016/10/Run_all_specs_in_Jasmine.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11913" class="wp-caption-text">run_all_specs_in_jasmine</p></div>
<p>Happy coding!.</p>
<h2><strong>Conclusion</strong></h2>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><strong>Your turn. What do you think?</strong></h2>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/writing-javascript-tests-using-jasmine-framework/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Programmatically Change The Element Or Page Into Full Screen Mode</title>
		<link>https://sibeeshpassion.com/programmatically-change-the-element-or-page-into-full-screen-mode/</link>
					<comments>https://sibeeshpassion.com/programmatically-change-the-element-or-page-into-full-screen-mode/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 07 Mar 2016 00:00:49 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Client Side API]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Page Into Full Screen Mode]]></category>
		<category><![CDATA[requestFullscreen]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11332</guid>

					<description><![CDATA[In this article we are going to see how we can change any element or any page into full screen mode programmatically. To do this requirement we are going to use client side API requestFullscreen . To make it compatible to all the browsers, we will be using separate API calls for each browsers. By using requestFullscreen , you can easily make the items to be viewable in a full screen mode. That&#8217;s cool right? You can use Video&#8217;s, Audio&#8217;s, Images, Pages or anything. Now shall we go and see this in detail? I hope you will like this. Download [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see how we can change any element or any page into full screen mode programmatically. To do this requirement we are going to use client side API <em>requestFullscreen </em>. To make it compatible to all the browsers, we will be using separate API calls for each browsers. By using <em>requestFullscreen </em>, you can easily make the items to be viewable in a full screen mode. That&#8217;s cool right? You can use Video&#8217;s, Audio&#8217;s, Images, Pages or anything. Now shall we go and see this in detail? I hope you will like this.</p>
<p><strong>Download the source code</strong></p>
<p>You can always download the source code here: 	</p>
<li><a href="http://sibeeshpassion.com/Download/Programmatically_Change_The_Element_Or_Page_Into_Full_Screen_Mode.rar" target="_blank">Programmatically Change The Element Or Page Into Full Screen Mode</a></li>
<p><strong>Background</strong></p>
<p>Yesterday I have got a requirement to do the full screen option programmatically in one of my application, I was required to open a chart, which is already being loaded to a page, in full screen mode. I have done that with the help of full screen API. Here I am going to show you that. Now we will start our coding. I hope you will enjoy reading. </p>
<p><strong>Create an Empty Website in Visual Studio</strong></p>
<p>Click File-> New-> Web Site.  </p>
<div id="attachment_11325" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500.png"><img decoding="async" aria-describedby="caption-attachment-11325" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500.png" alt="Empty Website In Visual Studio" width="650" height="449" class="size-full wp-image-11325" srcset="/wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500.png 650w, /wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500-300x207.png 300w, /wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500-160x110.png 160w, /wp-content/uploads/2016/03/Empty-Website-In-Visual-Studio-e1456922541500-400x276.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11325" class="wp-caption-text">Empty Website In Visual Studio</p></div>
<p><strong>Create a new HTML page</strong></p>
<p>Now create a new page, start coding.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Programmatically Change The Element Or Page Into Full Screen Mode&lt;/title&gt;<br />
    &lt;meta charset=&quot;utf-8&quot; /&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><strong>Using The Code</strong></p>
<p>We will be using pure JavaScript code to do this requirement. Firs of all create the container element and one other element in which we can fire the full screen function in on click event. </p>
<p>[html]<br />
  &lt;div id=&quot;container&quot; align=&quot;center&quot;&gt;&lt;/div&gt;<br />
    &lt;img src=&quot;full_screen.png&quot; onclick=&quot;changeToFullScreen()&quot; title=&quot;Click to change to full screen&quot;/&gt;<br />
[/html]</p>
<p>Here <em>changeToFullScreen()</em> is the function which does the task.</p>
<p>[js]<br />
 &lt;script&gt;<br />
        function changeToFullScreen() {<br />
            var itm = document.getElementById(&quot;container&quot;);<br />
            if (itm.requestFullscreen) {<br />
                itm.requestFullscreen();<br />
            } else if (itm.msRequestFullscreen) {<br />
                itm.msRequestFullscreen();<br />
            } else if (itm.mozRequestFullScreen) {<br />
                itm.mozRequestFullScreen();<br />
            } else if (itm.webkitRequestFullscreen) {<br />
                itm.webkitRequestFullscreen();<br />
            }<br />
        }<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>Now if you run your page in Google Chrome and fire the function, you will be given an output as preceding. </p>
<div id="attachment_11333" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome_Error-e1456985687909.png"><img decoding="async" aria-describedby="caption-attachment-11333" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome_Error-e1456985687909.png" alt="Chnage_Element_To_Full_Screen_In_Google_Chrome_Error" width="650" height="487" class="size-full wp-image-11333" srcset="/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome_Error-e1456985687909.png 650w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome_Error-e1456985687909-300x225.png 300w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome_Error-e1456985687909-400x300.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11333" class="wp-caption-text">Chnage_Element_To_Full_Screen_In_Google_Chrome_Error</p></div>
<p>As you can see that the window is opened in full screen, but not the element. To fix this, you must add a custom CSS style as follows. This is a hot fix which is applicable only to Google Chrome.</p>
<p>[css]<br />
#container:-webkit-full-screen {<br />
            width: 100%;<br />
            height: 100%;<br />
        }<br />
[/css]</p>
<p>Now run your page again, and make sure the fix is applied. </p>
<div id="attachment_11334" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome-e1456987149761.png"><img decoding="async" aria-describedby="caption-attachment-11334" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome-e1456987149761.png" alt="Chnage_Element_To_Full_Screen_In_Google_Chrome" width="650" height="588" class="size-full wp-image-11334" srcset="/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome-e1456987149761.png 650w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome-e1456987149761-300x271.png 300w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_In_Google_Chrome-e1456987149761-400x362.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11334" class="wp-caption-text">Chnage_Element_To_Full_Screen_In_Google_Chrome</p></div>
<p>Now if you want to escape from full screen whenever user press any keys, you can do that too. You can add a new function as follows.</p>
<p>[js]<br />
function changeToFullScreenOnKeyPress() {<br />
            if (!document.fullscreenElement &amp;&amp; !document.mozFullScreenElement &amp;&amp; !document.webkitFullscreenElement &amp;&amp; !document.msFullscreenElement) {<br />
                if (document.documentElement.requestFullscreen) {<br />
                    document.documentElement.requestFullscreen();<br />
                } else if (document.documentElement.msRequestFullscreen) {<br />
                    document.documentElement.msRequestFullscreen();<br />
                } else if (document.documentElement.mozRequestFullScreen) {<br />
                    document.documentElement.mozRequestFullScreen();<br />
                } else if (document.documentElement.webkitRequestFullscreen) {<br />
                    document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);<br />
                }<br />
            } else {<br />
                if (document.exitFullscreen) {<br />
                    document.exitFullscreen();<br />
                } else if (document.msExitFullscreen) {<br />
                    document.msExitFullscreen();<br />
                } else if (document.mozCancelFullScreen) {<br />
                    document.mozCancelFullScreen();<br />
                } else if (document.webkitExitFullscreen) {<br />
                    document.webkitExitFullscreen();<br />
                }<br />
            }<br />
        }<br />
[/js]</p>
<p>And you can call this function in <em>keydown</em> event as preceding.</p>
<p>[js]<br />
document.addEventListener(&quot;keydown&quot;, function (e) {<br />
            changeToFullScreenOnKeyPress();<br />
        }, false);<br />
[/js]</p>
<p>Run your page again and notice that the full screen is getting escaped whenever you press any keys. </p>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Programmatically Change The Element Or Page Into Full Screen Mode&lt;/title&gt;<br />
    &lt;meta charset=&quot;utf-8&quot; /&gt;<br />
    &lt;script&gt;<br />
        function changeToFullScreen() {<br />
            var itm = document.getElementById(&quot;container&quot;);<br />
            if (itm.requestFullscreen) {<br />
                itm.requestFullscreen();<br />
            } else if (itm.msRequestFullscreen) {<br />
                itm.msRequestFullscreen();<br />
            } else if (itm.mozRequestFullScreen) {<br />
                itm.mozRequestFullScreen();<br />
            } else if (itm.webkitRequestFullscreen) {<br />
                itm.webkitRequestFullscreen();<br />
            }<br />
        }<br />
        function changeToFullScreenOnKeyPress() {<br />
            if (!document.fullscreenElement &amp;&amp; !document.mozFullScreenElement &amp;&amp; !document.webkitFullscreenElement &amp;&amp; !document.msFullscreenElement) {<br />
                if (document.documentElement.requestFullscreen) {<br />
                    document.documentElement.requestFullscreen();<br />
                } else if (document.documentElement.msRequestFullscreen) {<br />
                    document.documentElement.msRequestFullscreen();<br />
                } else if (document.documentElement.mozRequestFullScreen) {<br />
                    document.documentElement.mozRequestFullScreen();<br />
                } else if (document.documentElement.webkitRequestFullscreen) {<br />
                    document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);<br />
                }<br />
            } else {<br />
                if (document.exitFullscreen) {<br />
                    document.exitFullscreen();<br />
                } else if (document.msExitFullscreen) {<br />
                    document.msExitFullscreen();<br />
                } else if (document.mozCancelFullScreen) {<br />
                    document.mozCancelFullScreen();<br />
                } else if (document.webkitExitFullscreen) {<br />
                    document.webkitExitFullscreen();<br />
                }<br />
            }<br />
        }<br />
        document.addEventListener(&quot;keydown&quot;, function (e) {<br />
            changeToFullScreenOnKeyPress();<br />
        }, false);<br />
    &lt;/script&gt;<br />
    &lt;style&gt;<br />
        #container:-webkit-full-screen {<br />
            width: 100%;<br />
            height: 100%;<br />
        }<br />
        #container<br />
        {<br />
            width:72px;<br />
            height:148px;<br />
            background-image:url(&#8216;sibeeshpassionLogoSmall.png&#8217;);<br />
        }<br />
    &lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;div id=&quot;container&quot; align=&quot;center&quot;&gt;&lt;/div&gt;<br />
    &lt;img src=&quot;full_screen.png&quot; onclick=&quot;changeToFullScreen()&quot; title=&quot;Click to change to full screen&quot;/&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<blockquote><p> Here <em>msRequestFullscreen</em>, <em>mozRequestFullScreen</em>, <em>webkitRequestFullscreen</em> is for Internet Explorer, Mozilla Firefox, Google Chrome respectively.</p></blockquote>
<p>We have done everything needed, Now it is time to see the output.</p>
<p><strong>Output</strong></p>
<div id="attachment_11335" style="width: 246px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Click.png"><img decoding="async" aria-describedby="caption-attachment-11335" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Click.png" alt="Chnage_Element_To_Full_Screen_Click" width="236" height="255" class="size-full wp-image-11335" /></a><p id="caption-attachment-11335" class="wp-caption-text">Chnage_Element_To_Full_Screen_Click</p></div>
<div id="attachment_11336" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output.png"><img decoding="async" aria-describedby="caption-attachment-11336" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-1024x575.png" alt="Chnage_Element_To_Full_Screen_Output" width="634" height="356" class="size-large wp-image-11336" srcset="/wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-1024x575.png 1024w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-300x169.png 300w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-768x431.png 768w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-400x225.png 400w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output-1068x600.png 1068w, /wp-content/uploads/2016/03/Chnage_Element_To_Full_Screen_Output.png 1362w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11336" class="wp-caption-text">Chnage_Element_To_Full_Screen_Output</p></div>
<p>Have a happy coding.</p>
<p><strong>References</strong></p>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API" target="_blank">Fullscreen_API</a></li>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/programmatically-change-the-element-or-page-into-full-screen-mode/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Hoisting In JavaScript</title>
		<link>https://sibeeshpassion.com/hoisting-in-javascript/</link>
					<comments>https://sibeeshpassion.com/hoisting-in-javascript/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 06 Nov 2015 12:19:21 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Hoisting]]></category>
		<category><![CDATA[Javascript]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10955</guid>

					<description><![CDATA[In this post we will discuss the importance and limitations of Hoisting in JavaScript. We all writes client side codes. Right? But few of you might not be aware of the term Hoisting. Hoisting is one of the default behaviour of JavaScript, it is the process of moving all the declarations of the variables to the top of the current function or scope. In this post we will explain this Hoisting in detail with some examples. I hope you will like this. Background I used to spend more time with the client side codes rather than server side codes. In [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss the importance and limitations of Hoisting in <a href="http://sibeeshpassion.com/category/javascript/" target="_blank">JavaScript</a>. We all writes client side codes. Right? But few of you might not be aware of the term Hoisting. Hoisting is one of the default behaviour of JavaScript, it is the process of moving all the declarations of the variables to the top of the current function or scope. In this post we will explain this Hoisting in detail with some examples. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>I used to spend more time with the client side codes rather than server side codes. In my thought is is always good if you do the formation of your data in client side instead doing it in the server side. Client side loops are always faster than the server side ones. As a client side code developer, you must understand the word Hoisting in JavaScript. Here we will discuss that.</p>
<p><strong>Using the code</strong></p>
<p>Before going through we need to know some facts in JavaScript. </p>
<p><em>Do you know?</em></p>
<p>In JavaScript we can use any variable before it is declared or a variable can be declared after it is used. </p>
<p>For Example: </p>
<p>The below two scripts will return same output.</p>
<p>[js]<br />
&lt;script&gt;<br />
x = 5;<br />
alert(x);<br />
var x;<br />
&lt;/script&gt;<br />
[/js]</p>
<p>And </p>
<p>[js]<br />
&lt;script&gt;<br />
var x;<br />
x = 5;<br />
alert(x);<br />
&lt;/script&gt;<br />
[/js]</p>
<p><strong>Limitations of Hoisting</strong></p>
<p>Even though the process of Hosting will move the declarations to the top, there is some limitations too. We will discuss it here now.</p>
<blockquote><p>Initializing a variable can not be Hoisted or In simple JavaScript Hoists declarations not initializations. </p></blockquote>
<p>For Example:</p>
<p>The below scripts will give different outputs.</p>
<p>[js]<br />
&lt;script&gt;<br />
var x = 2;<br />
var y = 4;<br />
alert(x+y);<br />
&lt;/script&gt;<br />
[/js]</p>
<p>This will give you an output of 6.</p>
<p>And </p>
<p>[js]<br />
&lt;script&gt;<br />
var x = 2;<br />
alert(x+y);<br />
var y = 4;<br />
&lt;/script&gt;<br />
[/js]</p>
<p>This will give you an output of NaN. Since we are initializing the value of y, the JavaScript Hoisting is not happening, so the y value will be undefined. The JavaScript will consider that y is not yet declared. </p>
<p>So the second example is same as of below.</p>
<p>[js]<br />
&lt;script&gt;<br />
var x = 2;<br />
var y;<br />
alert(x+y);<br />
y = 4;<br />
&lt;/script&gt;<br />
[/js]</p>
<p>This will give you an output of NaN.</p>
<div id="attachment_10956" style="width: 403px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Hoisting-In-JavaScript.png"><img decoding="async" aria-describedby="caption-attachment-10956" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Hoisting-In-JavaScript.png" alt="Hoisting In JavaScript" width="393" height="207" class="size-full wp-image-10956" srcset="/wp-content/uploads/2015/11/Hoisting-In-JavaScript.png 393w, /wp-content/uploads/2015/11/Hoisting-In-JavaScript-300x158.png 300w" sizes="(max-width: 393px) 100vw, 393px" /></a><p id="caption-attachment-10956" class="wp-caption-text">Hoisting In JavaScript</p></div>
<p><strong>Conclusion</strong></p>
<p>Since we are all developers, it is always makes things simple. So much complexity in software comes from trying to make one thing do two things. So always declare your variables on top of your function or scope. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/hoisting-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Regex to remove a word from a string</title>
		<link>https://sibeeshpassion.com/regex-to-remove-a-word-from-a-string/</link>
					<comments>https://sibeeshpassion.com/regex-to-remove-a-word-from-a-string/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 02 Nov 2015 10:13:52 +0000</pubDate>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Find a word from a string]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery regex]]></category>
		<category><![CDATA[Regex to remove a word from a string]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10890</guid>

					<description><![CDATA[In this post we will see how we can remove a particular word from a string entirely in jQuery. [js] var newString= oldString.replace(/Unspecified/g, &#8221;); [/js] Here I am removing the word Unspecified from my variable oldString. Please see my other posts related to JQuery here: JQuery Posts Kindest Regards Sibeesh Venu]]></description>
										<content:encoded><![CDATA[<p>In this post we will see how we can remove a particular word from a string entirely in <a href="http://sibeeshpassion.com/category/jquery" target="_blank">jQuery</a>. </p>
<p>[js]<br />
var newString= oldString.replace(/Unspecified/g, &#8221;);<br />
[/js]</p>
<p>Here I am removing the word Unspecified from my variable oldString. </p>
<p>Please see my other posts related to JQuery here: <a href="http://sibeeshpassion.com/tag/jquery/" target="_blank">JQuery Posts</a></p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/regex-to-remove-a-word-from-a-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Load Data To Grid On Sroll</title>
		<link>https://sibeeshpassion.com/load-data-to-grid-on-sroll/</link>
					<comments>https://sibeeshpassion.com/load-data-to-grid-on-sroll/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 02 Nov 2015 06:09:36 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQWidgets]]></category>
		<category><![CDATA[JQX Grid]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[jQWidget]]></category>
		<category><![CDATA[Load data dynamically]]></category>
		<category><![CDATA[Load Data To Grid On Sroll]]></category>
		<category><![CDATA[rendergridrows]]></category>
		<category><![CDATA[virtualmode]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10886</guid>

					<description><![CDATA[In this post we will discuss about how we can load data to a grid on scroll event. As you all know Grid is a main control in every dashboard. Every company uses a grid control for showing reports or any kind of data. Hence it is widely used, it is important that the grid must be loaded faster. So the performance of the grid control matters a lot. Isn&#8217;t it? Here in this post we are going to do a task which will increase the performance of the grid since we are going to load the data as per [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss about how we can load data to a grid on scroll event. As you all know Grid is a main control in every dashboard. Every company uses a grid control for showing reports or any kind of data. Hence it is widely used, it is important that the grid must be loaded faster. So the performance of the grid control matters a lot. Isn&#8217;t it? Here in this post we are going to do a task which will increase the performance of the grid since we are going to load the data as per user request (on scrolling down). Sounds cool?. Normally what we do is, we will load all the data to the grid in a head shot, the problem in this manner is, it will take ages to load the full data to grid. Hence the user will close your application and the won&#8217;t return back. That is sad thing right? So we will concentrate on the performance part now. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>I am working in a dashboard application. So for me performance was the main criteria to take care. We have used server side paging to improve the performance. This I will share in my next article. Now we will try to load a client side data on demand. Let us say when ever user scroll down. Sounds fine? Ok let us start then.</p>
<p><strong>Using the code</strong></p>
<p>To show this demo, I am using jQWidget jQX Grid control. If you are new to jQX Grid, you can find out some introduction here: <a href="http://sibeeshpassion.com/category/products/jqwidgets/" target="_blank">jQWidget JQX Grid</a></p>
<p>Now we are going to load the grid first. I hope you have already checked how to load the grid. Please see the below code. </p>
<p><em>Create an HTML page</em></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html lang=&quot;en&quot;&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Load Data To Grid On Scroll  &#8211; Sibeesh Passion&lt;/title&gt;<br />
   &lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;h3&gt;Load Data To Grid On Scroll  &#8211; Sibeesh Passion&lt;/h3&gt;<br />
    &lt;br /&gt;<br />
    &lt;div id=&quot;jqxgrid&quot;&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p><em>Add the needed references</em></p>
<p>[html]<br />
 &lt;script src=&quot;jquery-1.9.1.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxcore.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdata.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxbuttons.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxscrollbar.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxlistbox.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdropdownlist.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxmenu.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.filter.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.sort.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.selection.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.pager.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.columnsresize.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.columnsreorder.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.export.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdata.export.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdatatable.js&quot;&gt;&lt;/script&gt;<br />
    &lt;link href=&quot;JQXItems/jqwidgets/styles/jqx.base.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
[/html]</p>
<p>Here comes the main part.</p>
<p><strong>Grid Settings or Grid Initialization</strong></p>
<p>[js]<br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
         $(document).ready(function () {<br />
             // prepare the data<br />
             var data = new Array();<br />
             var firstNames =<br />
             [<br />
                 &quot;Sibeesh&quot;, &quot;Ajay&quot;, &quot;Ansary&quot;, &quot;Aghil&quot;, &quot;Shanto&quot;, &quot;Libin&quot;, &quot;Vignesh&quot;, &quot;Ramesh&quot;, &quot;Sathian&quot;, &quot;Elango&quot;, &quot;karthik&quot;<br />
             ];</p>
<p>             var lastNames =<br />
             [<br />
                 &quot;Venu&quot;, &quot;Bhasy&quot;, &quot;Rasheed&quot;, &quot;Ghosh&quot;, &quot;Thomas&quot;, &quot;Lawrence&quot;, &quot;Vicky&quot;, &quot;K&quot;, &quot;K&quot;, &quot;S&quot;, &quot;Srinivasan&quot;<br />
             ];</p>
<p>             var productNames =<br />
             [<br />
                 &quot;Shoe&quot;, &quot;Sandals&quot;, &quot;Shampoo&quot;, &quot;Soap&quot;, &quot;Hair Lotion&quot;, &quot;Creams&quot;, &quot;Bags&quot;, &quot;Watch&quot;, &quot;Books&quot;, &quot;Mobile&quot;, &quot;Tab&quot;, &quot;Laptop&quot;<br />
             ];</p>
<p>             var priceValues =<br />
             [<br />
                 &quot;2.25&quot;, &quot;1.5&quot;, &quot;3.0&quot;, &quot;3.3&quot;, &quot;4.5&quot;, &quot;3.6&quot;, &quot;3.8&quot;, &quot;2.5&quot;, &quot;5.0&quot;, &quot;20.75&quot;, &quot;13.25&quot;, &quot;124.0&quot;<br />
             ];</p>
<p>             // generate sample data.<br />
             var generatedata = function (startindex, endindex) {<br />
                 var data = {};<br />
                 for (var i = startindex; i &lt; endindex; i++) {<br />
                     var row = {};<br />
                     var productindex = Math.floor(Math.random() * productNames.length);<br />
                     var price = parseFloat(priceValues[productindex]);<br />
                     var quantity = 1 + Math.round(Math.random() * 10);</p>
<p>                     row[&quot;id&quot;] = i;<br />
                     row[&quot;firstname&quot;] = firstNames[Math.floor(Math.random() * firstNames.length)];<br />
                     row[&quot;lastname&quot;] = lastNames[Math.floor(Math.random() * lastNames.length)];<br />
                     row[&quot;productname&quot;] = productNames[productindex];<br />
                     row[&quot;price&quot;] = price;<br />
                     row[&quot;quantity&quot;] = quantity;<br />
                     row[&quot;total&quot;] = price * quantity;</p>
<p>                     data[i] = row;<br />
                 }<br />
                 return data;<br />
             }</p>
<p>             var source =<br />
             {<br />
                 datatype: &quot;array&quot;,<br />
                 localdata: {},<br />
                 totalrecords: 1000000<br />
             };</p>
<p>             // load virtual data.<br />
             var rendergridrows = function (params) {<br />
                 var data = generatedata(params.startindex, params.endindex);<br />
                 return data;<br />
             }<br />
             var dataAdapter = new $.jqx.dataAdapter(source);</p>
<p>             $(&quot;#jqxgrid&quot;).jqxGrid(<br />
             {<br />
                 width: 850,<br />
                 source: dataAdapter,<br />
                 virtualmode: true,<br />
                 rendergridrows: rendergridrows,<br />
                 columns: [<br />
                     { text: &#8216;Id&#8217;, datafield: &#8216;id&#8217;, width: 100 },<br />
                     { text: &#8216;First Name&#8217;, datafield: &#8216;firstname&#8217;, width: 120 },<br />
                     { text: &#8216;Last Name&#8217;, datafield: &#8216;lastname&#8217;, width: 120 },<br />
                     { text: &#8216;Product&#8217;, datafield: &#8216;productname&#8217;, width: 180 },<br />
                     { text: &#8216;Quantity&#8217;, datafield: &#8216;quantity&#8217;, width: 80, cellsalign: &#8216;right&#8217; },<br />
                     { text: &#8216;Unit Price&#8217;, datafield: &#8216;price&#8217;, width: 90, cellsalign: &#8216;right&#8217;, cellsformat: &#8216;c2&#8217; },<br />
                     { text: &#8216;Total&#8217;, datafield: &#8216;total&#8217;, cellsalign: &#8216;right&#8217;, cellsformat: &#8216;c2&#8217; }<br />
                 ]<br />
             });<br />
         });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>As you can find out in the above code we are generating the data dynamically using a <a href="http://sibeeshpassion.com/function-declaration-and-function-expression/" target="_blank">function declaration</a> <em>generatedata</em>. </p>
<p>Have you noticed that in the grid settings we have given <em>virtualmode: true</em>. This is very important. This property is meant to be used for handling the dynamic data in grid. </p>
<p>And another property you must be aware of is <em>rendergridrows: rendergridrows</em>. This means, we are rendering the grid data on demand. Like when user change the pager or scroll. So we are going to call our <em>generatedata</em> function in the <em>rendergridrows</em>. We are passing the start index and end index to the function, so that the dynamic data won&#8217;t be repeated.</p>
<p>[js]<br />
var rendergridrows = function (params) {<br />
                 var data = generatedata(params.startindex, params.endindex);<br />
                 return data;<br />
             }<br />
[/js]</p>
<p>Once the data is ready, we will pass it to the source object and source object to dataAdapter and finally dataAdapter to grid.</p>
<p>Shall we check our output now? </p>
<p><strong>Output</strong></p>
<div id="attachment_10887" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll-e1446444313182.png"><img decoding="async" aria-describedby="caption-attachment-10887" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll-e1446444313182.png" alt="Load Data On Scroll" width="650" height="369" class="size-full wp-image-10887" srcset="/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll-e1446444313182.png 650w, /wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll-e1446444313182-300x170.png 300w, /wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll-e1446444313182-400x227.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10887" class="wp-caption-text">Load Data On Scroll</p></div>
<div id="attachment_10888" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll_1-e1446444357826.png"><img decoding="async" aria-describedby="caption-attachment-10888" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll_1-e1446444357826.png" alt="Load Data On Scroll" width="650" height="359" class="size-full wp-image-10888" srcset="/wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll_1-e1446444357826.png 650w, /wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll_1-e1446444357826-300x166.png 300w, /wp-content/uploads/2015/11/Load_Data_In_Grid_On_Scroll_1-e1446444357826-400x221.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10888" class="wp-caption-text">Load Data On Scroll</p></div>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html lang=&quot;en&quot;&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Load Data To Grid On Scroll  &#8211; Sibeesh Passion&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-1.9.1.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxcore.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdata.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxbuttons.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxscrollbar.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxlistbox.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdropdownlist.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxmenu.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.filter.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.sort.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.selection.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.pager.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.columnsresize.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.columnsreorder.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxgrid.export.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdata.export.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script type=&quot;text/javascript&quot; src=&quot;JQXItems/jqwidgets/jqxdatatable.js&quot;&gt;&lt;/script&gt;<br />
    &lt;link href=&quot;JQXItems/jqwidgets/styles/jqx.base.css&quot; rel=&quot;stylesheet&quot; /&gt;</p>
<p>     &lt;script type=&quot;text/javascript&quot;&gt;<br />
         $(document).ready(function () {<br />
             // prepare the data<br />
             var data = new Array();<br />
             var firstNames =<br />
             [<br />
                 &quot;Sibeesh&quot;, &quot;Ajay&quot;, &quot;Ansary&quot;, &quot;Aghil&quot;, &quot;Shanto&quot;, &quot;Libin&quot;, &quot;Vignesh&quot;, &quot;Ramesh&quot;, &quot;Sathian&quot;, &quot;Elango&quot;, &quot;karthik&quot;<br />
             ];</p>
<p>             var lastNames =<br />
             [<br />
                 &quot;Venu&quot;, &quot;Bhasy&quot;, &quot;Rasheed&quot;, &quot;Ghosh&quot;, &quot;Thomas&quot;, &quot;Lawrence&quot;, &quot;Vicky&quot;, &quot;K&quot;, &quot;K&quot;, &quot;S&quot;, &quot;Srinivasan&quot;<br />
             ];</p>
<p>             var productNames =<br />
             [<br />
                 &quot;Shoe&quot;, &quot;Sandals&quot;, &quot;Shampoo&quot;, &quot;Soap&quot;, &quot;Hair Lotion&quot;, &quot;Creams&quot;, &quot;Bags&quot;, &quot;Watch&quot;, &quot;Books&quot;, &quot;Mobile&quot;, &quot;Tab&quot;, &quot;Laptop&quot;<br />
             ];</p>
<p>             var priceValues =<br />
             [<br />
                 &quot;2.25&quot;, &quot;1.5&quot;, &quot;3.0&quot;, &quot;3.3&quot;, &quot;4.5&quot;, &quot;3.6&quot;, &quot;3.8&quot;, &quot;2.5&quot;, &quot;5.0&quot;, &quot;20.75&quot;, &quot;13.25&quot;, &quot;124.0&quot;<br />
             ];</p>
<p>             var generatedata = function (startindex, endindex) {<br />
                 var data = {};<br />
                 for (var i = startindex; i &lt; endindex; i++) {<br />
                     var row = {};<br />
                     var productindex = Math.floor(Math.random() * productNames.length);<br />
                     var price = parseFloat(priceValues[productindex]);<br />
                     var quantity = 1 + Math.round(Math.random() * 10);</p>
<p>                     row[&quot;id&quot;] = i;<br />
                     row[&quot;firstname&quot;] = firstNames[Math.floor(Math.random() * firstNames.length)];<br />
                     row[&quot;lastname&quot;] = lastNames[Math.floor(Math.random() * lastNames.length)];<br />
                     row[&quot;productname&quot;] = productNames[productindex];<br />
                     row[&quot;price&quot;] = price;<br />
                     row[&quot;quantity&quot;] = quantity;<br />
                     row[&quot;total&quot;] = price * quantity;</p>
<p>                     data[i] = row;<br />
                 }<br />
                 return data;<br />
             }</p>
<p>             var source =<br />
             {<br />
                 datatype: &quot;array&quot;,<br />
                 localdata: {},<br />
                 totalrecords: 1000000<br />
             };</p>
<p>             // load virtual data.<br />
             var rendergridrows = function (params) {<br />
                 var data = generatedata(params.startindex, params.endindex);<br />
                 return data;<br />
             }<br />
             var dataAdapter = new $.jqx.dataAdapter(source);</p>
<p>             $(&quot;#jqxgrid&quot;).jqxGrid(<br />
             {<br />
                 width: 850,<br />
                 source: dataAdapter,<br />
                 virtualmode: true,<br />
                 rendergridrows: rendergridrows,<br />
                 columns: [<br />
                     { text: &#8216;Id&#8217;, datafield: &#8216;id&#8217;, width: 100 },<br />
                     { text: &#8216;First Name&#8217;, datafield: &#8216;firstname&#8217;, width: 120 },<br />
                     { text: &#8216;Last Name&#8217;, datafield: &#8216;lastname&#8217;, width: 120 },<br />
                     { text: &#8216;Product&#8217;, datafield: &#8216;productname&#8217;, width: 180 },<br />
                     { text: &#8216;Quantity&#8217;, datafield: &#8216;quantity&#8217;, width: 80, cellsalign: &#8216;right&#8217; },<br />
                     { text: &#8216;Unit Price&#8217;, datafield: &#8216;price&#8217;, width: 90, cellsalign: &#8216;right&#8217;, cellsformat: &#8216;c2&#8217; },<br />
                     { text: &#8216;Total&#8217;, datafield: &#8216;total&#8217;, cellsalign: &#8216;right&#8217;, cellsformat: &#8216;c2&#8217; }<br />
                 ]<br />
             });<br />
         });<br />
    &lt;/script&gt;</p>
<p>&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;h3&gt;Load Data To Grid On Scroll  &#8211; Sibeesh Passion&lt;/h3&gt;<br />
    &lt;br /&gt;<br />
    &lt;div id=&quot;jqxgrid&quot;&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/load-data-to-grid-on-sroll/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Function Declaration And Function Expression</title>
		<link>https://sibeeshpassion.com/function-declaration-and-function-expression/</link>
					<comments>https://sibeeshpassion.com/function-declaration-and-function-expression/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 21 Oct 2015 00:59:00 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Difference between function declaration and function expression]]></category>
		<category><![CDATA[Function Declaration And Function Expression]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10821</guid>

					<description><![CDATA[In this post we will see the basic difference between function declaration and function expression in jQuery and JavaScript. Sometimes the developer&#8217;s getting confused between these two topics(Shhhh I ma saying about the starters like me). Basically both are same. Only difference is depends on how you handle or treat these two. We will see a basic demo here to ensure the difference between function declaration and expression. I hope you will like this. Here I am using jQuery 2.0.2 version, you can use whichever version you like. Background In my projects I am using both function declarations and function [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see the basic difference between function declaration and function expression in jQuery and JavaScript. Sometimes the developer&#8217;s getting confused between these two topics(Shhhh I ma saying about the starters like me). Basically both are same. Only difference is depends on how you handle or treat these two. We will see a basic demo here to ensure the difference between function declaration and expression. I hope you will like this.</p>
<blockquote><p>Here I am using jQuery 2.0.2 version, you can use whichever version you like. </p></blockquote>
<p><strong>Background</strong></p>
<p>In my projects I am using both function declarations and function expressions. So I thought to highlight some basic difference between them, so that it may help someone. </p>
<p><strong>Basic Difference Between Function Declaration And Function Definition</strong></p>
<li>Function declarations are loaded first, that is before any codes</li>
<li>Function expressions are loaded when the interpreter reaches that particular line of code.</li>
<li>Basically we can call any code only after the declarations are loaded</li>
<p>We will try to find out this difference with a demo.</p>
<p><strong>Using the code</strong></p>
<p>First thing you need to do is create a page.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Function Declaration VS Expression &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
   Function Declaration VS Expression &#8211; Sibeesh Passion<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>Then you need to include the script needed.</p>
<p>[js]<br />
&lt;script src=&quot;http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Now we will create a function declaration as follows. </p>
<p>[js]<br />
&lt;script&gt;<br />
        $(document).ready(function () {<br />
		   alert(myFunctionDeclaration());<br />
           function myFunctionDeclaration()<br />
		   {<br />
				return &#8216;myFunctionDeclaration is called&#8217;;<br />
		   }<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>What will be the output of this?</p>
<div id="attachment_10822" style="width: 391px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png"><img decoding="async" aria-describedby="caption-attachment-10822" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png" alt="Function Declaration And Function Expression " width="381" height="231" class="size-full wp-image-10822" srcset="/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png 381w, /wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression-300x182.png 300w" sizes="(max-width: 381px) 100vw, 381px" /></a><p id="caption-attachment-10822" class="wp-caption-text">Function Declaration And Function Expression</p></div>
<p>Now we will change our script as follows. </p>
<p>[js]<br />
&lt;script&gt;<br />
        $(document).ready(function () {<br />
           function myFunctionDeclaration()<br />
		   {<br />
				return &#8216;myFunctionDeclaration is called&#8217;;<br />
		   }<br />
		   alert(myFunctionDeclaration());<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>This will also returns the same output.</p>
<div id="attachment_10822" style="width: 391px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png"><img decoding="async" aria-describedby="caption-attachment-10822" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png" alt="Function Declaration And Function Expression " width="381" height="231" class="size-full wp-image-10822" srcset="/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression.png 381w, /wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression-300x182.png 300w" sizes="(max-width: 381px) 100vw, 381px" /></a><p id="caption-attachment-10822" class="wp-caption-text">Function Declaration And Function Expression</p></div>
<p>Now we will create a function expression as follows. </p>
<p>[js]<br />
&lt;script&gt;<br />
        $(document).ready(function () {<br />
		  alert(myFunctionExpression());<br />
		   var myFunctionExpression = function()<br />
		   {<br />
				return &#8216;myFunctionExpression is called&#8217;;<br />
		   }<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>What may be the output of this? We will check it now. </p>
<div id="attachment_10823" style="width: 427px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression1.png"><img decoding="async" aria-describedby="caption-attachment-10823" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression1.png" alt="Function Declaration And Function Expression " width="417" height="282" class="size-full wp-image-10823" srcset="/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression1.png 417w, /wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression1-300x203.png 300w, /wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression1-400x271.png 400w" sizes="(max-width: 417px) 100vw, 417px" /></a><p id="caption-attachment-10823" class="wp-caption-text">Function Declaration And Function Expression</p></div>
<p>As you can see, instead of giving an alert it is throwing an error <em>Uncaught TypeError: myFunctionExpression is not a function</em> in the console. It is just because the function expression is not yet loaded. You are trying to call that expression before it loads.</p>
<p>So what we can do to make it work? Simple, just change the script as follows.</p>
<p>[js]<br />
&lt;script&gt;<br />
        $(document).ready(function () {<br />
                   var myFunctionExpression = function()<br />
		   {<br />
				return &#8216;myFunctionExpression is called&#8217;;<br />
		   }<br />
		   alert(myFunctionExpression());<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>Now you will get an alert as follows.</p>
<div id="attachment_10824" style="width: 397px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression2.png"><img decoding="async" aria-describedby="caption-attachment-10824" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression2.png" alt="Function Declaration And Function Expression " width="387" height="207" class="size-full wp-image-10824" srcset="/wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression2.png 387w, /wp-content/uploads/2015/10/Function_Declaration_And_Function_Expression2-300x160.png 300w" sizes="(max-width: 387px) 100vw, 387px" /></a><p id="caption-attachment-10824" class="wp-caption-text">Function Declaration And Function Expression</p></div>
<p>That is all. I hope you know the difference between function declaration and function expression now. </p>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Function Declaration VS Expression &#8211; Sibeesh Passion&lt;/title&gt;<br />
    &lt;script src=&quot;http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        $(document).ready(function () {</p>
<p>		   var myFunctionExpression = function()<br />
		   {<br />
				return &#8216;myFunctionExpression is called&#8217;;<br />
		   }<br />
		   alert(myFunctionExpression());<br />
		   alert(myFunctionDeclaration());<br />
           function myFunctionDeclaration()<br />
		   {<br />
				return &#8216;myFunctionDeclaration is called&#8217;;<br />
		   }<br />
        });<br />
    &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    Function Declaration VS Expression &#8211; Sibeesh Passion<br />
	&lt;div class=&quot;first&quot;&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/function-declaration-and-function-expression/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>jQuery no-conflict And Using Different Versions Of JQuery</title>
		<link>https://sibeeshpassion.com/jquery-no-conflict-and-using-different-versions-of-jquery/</link>
					<comments>https://sibeeshpassion.com/jquery-no-conflict-and-using-different-versions-of-jquery/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 12 Oct 2015 12:03:11 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[$ and $j as jquery]]></category>
		<category><![CDATA[jquery events]]></category>
		<category><![CDATA[jquery no-conflict]]></category>
		<category><![CDATA[Using Different Versions Of JQuery]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10793</guid>

					<description><![CDATA[In this post we will see what is jQuery no-conflict and what is the importance of jQuery no-conflict. We will also learn how can we use different versions of JQuery in the same page according to your need. jQuery no-conflict is an option given by the jQuery to over come the conflicts between the different js frameworks or libraries. When we use jQuery no-conflict mode, we are replacing the $ to a new variable and assign to jQuery. Here in this post we will explain this feature in deep and we will also create a demo of using different versions [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see what is jQuery no-conflict and what is the importance of jQuery no-conflict. We will also learn how can we use different versions of JQuery in the same page according to your need. jQuery no-conflict is an option given by the jQuery to over come the conflicts between the different js frameworks or libraries. When we use jQuery no-conflict mode, we are replacing the $ to a new variable and assign to jQuery. Here in this post we will explain this feature in deep and we will also create a demo of using different versions of jQuery together in one page. I hope you will like this. </p>
<p><strong>Download Source Code</strong></p>
<p>Please download the source code here: <a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQueryNoConflict.rar" target="_blank">jQuery noConflict</a></p>
<p><strong>Introduction</strong></p>
<p>As you all know, some other JavaScript libraries also uses the $ (Which is the default reference of jQuery) as a function or variable name as jQuery has. And in our development life, we are not at all strict to only jQuery, we may use lots of other libraries too. Isn&#8217;t it? I use different libraries in my projects to accomplish different tasks. So what will happen when we use those libraries? There will be conflicts between those libraries right since they all use $ as the variable name. The situation is really bad.</p>
<p>So we have only one chocolate and more number of winners, in real life we can just cut the chocolate into the number of winners, right? </p>
<div id="attachment_10794" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/Dogs-Sharing-Food-e1444646199502.jpg"><img decoding="async" aria-describedby="caption-attachment-10794" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/Dogs-Sharing-Food-1024x768.jpg" alt="Dogs Sharing Food" width="634" height="476" class="size-large wp-image-10794" /></a><p id="caption-attachment-10794" class="wp-caption-text">Dogs Sharing Food</p></div>
<p>But that won&#8217;t be accepted in this case, so we have an another option, this option is introduced by jQuery and it is jQuery no-conflict. </p>
<p><strong>Background</strong></p>
<p>I always use different libraries in my project, thus sometimes I faced these problem in my project. So I thought of sharing with you all who are facing this problem.</p>
<p><strong>Using the code</strong></p>
<p>The first thing you want to do is creating an <a href="http://sibeeshpassion.com/category/html/" target="_blank">HTML </a>page.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;JQuery noConflict &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    JQuery noConflict &#8211; Sibeesh Passion<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>So what is next? Adding reference ? Yes.</p>
<p>[js]<br />
&lt;script src=&quot;prototype.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>So we are using prototype lowest version and jquery together, in this case you will face conflict errors, and please be noted that the new version of prototype.js doesn&#8217;t have any conflict with jQuery since they updated and given the fix. </p>
<p>So what to do if you found any issues? you just need to give the $ to prototype and assign a new variable to jquery as follows.</p>
<p>[js]<br />
 &lt;script&gt;<br />
        // Give $ back to prototype.js; create new alias to jQuery.<br />
        var $jq = jQuery.noConflict();<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>And now you can use $jq as the new jQuery reference.</p>
<p>[js]<br />
 &lt;script&gt;<br />
        $jq(document).ready(function () {<br />
            $jq(&quot;#btn&quot;).on(&#8216;click&#8217;, function () {<br />
                alert(&#8216;Clicked&#8217;);<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p><strong>Complete Code </strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;JQuery noConflict &#8211; Sibeesh Passion&lt;/title&gt;<br />
    &lt;script src=&quot;prototype.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
     &lt;script&gt;<br />
         // Give $ to prototype.js<br />
         var $jq = jQuery.noConflict();<br />
    &lt;/script&gt;<br />
    &lt;script&gt;<br />
        $jq(document).ready(function () {<br />
            $jq(&quot;#btn&quot;).on(&#8216;click&#8217;, function () {<br />
                alert(&#8216;Clicked&#8217;);<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    JQuery noConflict &#8211; Sibeesh Passion<br />
     &lt;br /&gt;<br />
    &lt;br /&gt;<br />
    &lt;br /&gt;<br />
     &lt;input type=&quot;button&quot; value=&quot;&quot; id=&#8217;btn&#8217; /&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>Sometimes we may end up in a situation to use different version of jQuery in the same page right? </p>
<p><strong>Situation I faced</strong></p>
<p>I was working in an old project which was handled by a team few years back, at that time I got a minor work to do in that project, to do the task I was in a need to add the latest version of jQuery since the entire project was using the old reference of jQuery. I was in a situation that I should not remove the old references and update with the new one, if I do that there might be some issues with other functionalities right? Since the project was already in live, I didn&#8217;t take that risk. So I added the new version and used jQuery noConflict to avoid the reference issues. </p>
<p><strong>Using the code</strong></p>
<p>Here I am going to give you a demo of now to use different version of jQuery in one page.</p>
<p>First of all please add the needed reference to your page.</p>
<p>[js]<br />
&lt;script src=&quot;JQuery%20Versions/jquery-1.9.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.10.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.3.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Please be noted that we have added jQuery 1.9.0,1.10.1,1.11.0,1.11.1,1.11.3 in our page. </p>
<p>Now we need to add some buttons in the UI, later we will bind the click events of the same buttons. </p>
<p>[html]<br />
 &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.9.0&quot; id=&#8217;btn190&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.10.1&quot; id=&#8217;btn1101&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.0&quot; id=&#8217;btn1110&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.1&quot; id=&#8217;btn1111&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.3&quot; id=&#8217;btn1113&#8242; /&gt;<br />
[/html]</p>
<p>What is next, so we have added the different jQuery versions. Now we will create different variable names for each versions. Is that fine?</p>
<p>[js]<br />
 &lt;script src=&quot;JQuery%20Versions/jquery-1.9.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery190 = jQuery.noConflict();<br />
        window.jQuery = jQuery190;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.10.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1101 = jQuery.noConflict();<br />
        window.jQuery = jQuery1101;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1110 = jQuery.noConflict();<br />
        window.jQuery = jQuery1110;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1111 = jQuery.noConflict();<br />
        window.jQuery = jQuery1111;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.3.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1113 = jQuery.noConflict();<br />
        window.jQuery = jQuery1113;<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>So now we have added variable names for all the versions right? The next thing we are going to do is to fire the click events for each versions. </p>
<p>[js]<br />
 &lt;script&gt;<br />
        jQuery190(document).ready(function ($) {<br />
            //The codes for jQuery 1-9-0<br />
            $(&quot;#btn190&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1101(document).ready(function ($) {<br />
            //The codes for jQuery 1-10-1<br />
            $(&quot;#btn1101&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1110(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-0<br />
            $(&quot;#btn1110&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1111(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-1<br />
            $(&quot;#btn1111&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1113(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-3<br />
            $(&quot;#btn1113&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>So if you run your page and click the buttons, you can find that the related codes only get fired. </p>
<div id="attachment_10797" style="width: 655px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery.png"><img decoding="async" aria-describedby="caption-attachment-10797" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery.png" alt="jQuery no-conflict And Using Different Versions Of JQuery" width="645" height="306" class="size-full wp-image-10797" srcset="/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery.png 645w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery-300x142.png 300w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery-400x190.png 400w" sizes="(max-width: 645px) 100vw, 645px" /></a><p id="caption-attachment-10797" class="wp-caption-text">jQuery no-conflict And Using Different Versions Of JQuery</p></div>
<div id="attachment_10798" style="width: 643px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_1.png"><img decoding="async" aria-describedby="caption-attachment-10798" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_1.png" alt="jQuery no-conflict And Using Different Versions Of JQuery" width="633" height="312" class="size-full wp-image-10798" srcset="/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_1.png 633w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_1-300x148.png 300w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_1-400x197.png 400w" sizes="(max-width: 633px) 100vw, 633px" /></a><p id="caption-attachment-10798" class="wp-caption-text">jQuery no-conflict And Using Different Versions Of JQuery</p></div>
<p>Now what if you comment out the variable declaration for jQuery version 1.11.3? </p>
<p>[js]<br />
//var jQuery1113 = jQuery.noConflict();<br />
        //window.jQuery = jQuery1113;<br />
[/js]</p>
<p>You will get an error says <em>Uncaught ReferenceError: jQuery1113 is not defined</em> in browser console. </p>
<div id="attachment_10799" style="width: 647px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2.png"><img decoding="async" aria-describedby="caption-attachment-10799" src="http://sibeeshpassion.com/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2.png" alt="jQuery no-conflict And Using Different Versions Of JQuery" width="637" height="336" class="size-full wp-image-10799" srcset="/wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2.png 637w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2-300x158.png 300w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2-600x315.png 600w, /wp-content/uploads/2015/10/jQuery_no-conflict_And_Using_Different_Versions_Of_JQuery_2-400x211.png 400w" sizes="(max-width: 637px) 100vw, 637px" /></a><p id="caption-attachment-10799" class="wp-caption-text">jQuery no-conflict And Using Different Versions Of JQuery</p></div>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Use JQuery Different Versions in One Page &#8211; Sibeesh Passion&lt;/title&gt;</p>
<p>    &lt;script src=&quot;JQuery%20Versions/jquery-1.9.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery190 = jQuery.noConflict();<br />
        window.jQuery = jQuery190;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.10.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1101 = jQuery.noConflict();<br />
        window.jQuery = jQuery1101;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1110 = jQuery.noConflict();<br />
        window.jQuery = jQuery1110;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var jQuery1111 = jQuery.noConflict();<br />
        window.jQuery = jQuery1111;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;JQuery%20Versions/jquery-1.11.3.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        //var jQuery1113 = jQuery.noConflict();<br />
        //window.jQuery = jQuery1113;<br />
    &lt;/script&gt;<br />
    &lt;script&gt;<br />
        jQuery190(document).ready(function ($) {<br />
            //The codes for jQuery 1-9-0<br />
            $(&quot;#btn190&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1101(document).ready(function ($) {<br />
            //The codes for jQuery 1-10-1<br />
            $(&quot;#btn1101&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1110(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-0<br />
            $(&quot;#btn1110&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1111(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-1<br />
            $(&quot;#btn1111&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
        jQuery1113(document).ready(function ($) {<br />
            //The codes for jQuery 1-11-3<br />
            $(&quot;#btn1113&quot;).on(&#8216;click&#8217;, function () {<br />
                alert($.fn.jquery);<br />
            })<br />
        });<br />
    &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    Use JQuery Different Versions in One Page<br />
    &lt;br /&gt;<br />
    &lt;br /&gt;<br />
    &lt;br /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.9.0&quot; id=&#8217;btn190&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.10.1&quot; id=&#8217;btn1101&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.0&quot; id=&#8217;btn1110&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.1&quot; id=&#8217;btn1111&#8242; /&gt;<br />
    &lt;input type=&quot;button&quot; value=&quot;Use jQuery 1.11.3&quot; id=&#8217;btn1113&#8242; /&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>That&#8217;s all.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Have you ever used different versions of jQuery in same page? Have you ever tried jQuery noConflict? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/jquery-no-conflict-and-using-different-versions-of-jquery/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>A Drag And Drop Game</title>
		<link>https://sibeeshpassion.com/a-drag-and-drop-game/</link>
					<comments>https://sibeeshpassion.com/a-drag-and-drop-game/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 20 Aug 2015 10:12:02 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Drag And Drop Game]]></category>
		<category><![CDATA[JQuery Drag]]></category>
		<category><![CDATA[JQuery Drop]]></category>
		<category><![CDATA[jquery functions]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=9831</guid>

					<description><![CDATA[[toc] Introduction In this post, we will create a drag and drop game which uses jquery drag drop functions. We will create two boxes, from one box we need to drag the content box and drop the same into another box. We will be using sortable function and its events. I hope you will like this game. Background For the last Independence day for India, I though to create a game related to the word &#8220;INDIA&#8221;. I created and hosted it in my website. Using the code First we will create an html5 page as follows. [html] &#60;!DOCTYPE html&#62; &#60;html&#62; [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In this post, we will create a drag and drop game which uses <a href="http://sibeeshpassion.com/tag/jquery/" target="_blank" rel="noopener">jquery</a> drag drop functions. We will create two boxes, from one box we need to drag the content box and drop the same into another box. We will be using sortable function and its events. I hope you will like this game.</p>
<h2><strong>Background</strong></h2>
<p>For the last <em>Independence day for India</em>, I though to create a game related to the word &#8220;INDIA&#8221;. I created and hosted it in my website.</p>
<h2><strong>Using the code</strong></h2>
<p>First we will create an <a href="http://sibeeshpassion.com/tag/html5/" target="_blank" rel="noopener">html5 </a>page as follows.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Find INDIA Game &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body id=&#8221;body&#8221;&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>And now we will set style to the body. <a href="http://sibeeshpassion.com/make-image-fit-to-the-screen/" target="_blank" rel="noopener">To set the background image fit to the screen</a> we will use the following styles.</p>
<p>[css]<br />
#body {<br />
background: url(&#8220;http://sibeeshpassion.com/content/images/indian%20flag%20banner.jpg&#8221;) no-repeat center center fixed;<br />
-webkit-background-size: cover;<br />
-moz-background-size: cover;<br />
-o-background-size: cover;<br />
background-size: cover;<br />
}<br />
[/css]</p>
<p>Now we can see page as follows.</p>
<div id="attachment_9841" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/FindIndiaImage-e1439998028998.png"><img decoding="async" aria-describedby="caption-attachment-9841" class="size-large wp-image-9841" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/FindIndiaImage-1024x536.png" alt="Make Image Fit To The Screen" width="634" height="332" /></a><p id="caption-attachment-9841" class="wp-caption-text">Make Image Fit To The Screen</p></div>
<p>Since we are going to create a client side game, it is necessary to load the jquery and jquery ui reference.</p>
<p>[js]<br />
&lt;script src=&#8221;jquery-2.0.2.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;jquery-ui.js&#8221;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Next we will create the drag able contents as follows.</p>
<p>[html]<br />
&lt;div class=&#8221;dragDiv&#8221;&gt;<br />
&lt;div id=&#8221;dragDivInner&#8221;&gt;<br />
&lt;div myid=&#8221;1&#8243; class=&#8221;droppable&#8221; myval=&#8221;I&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;2&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;3&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;6&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;7&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;8&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;9&#8243; class=&#8221;droppable&#8221; myval=&#8221;N&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;10&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;11&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;12&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;17&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;18&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;19&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;20&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;A&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;21&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;22&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;23&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;24&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;25&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;I&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;26&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;27&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;28&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;29&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;30&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;31&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;D&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;32&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;33&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;34&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;35&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;40&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>Now we need to set a div where we can drag contents to it.</p>
<p>[html]<br />
&lt;div class=&#8221;dropDiv&#8221;&gt;<br />
&lt;div id=&#8221;draggedContent&#8221; style=&#8221;display: none;&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>As it is a game, we must set the game rules also right?</p>
<p>[html]<br />
&lt;div id=&#8221;gamerules&#8221;&gt;<br />
&lt;ul&gt;<br />
&lt;li class=&#8221;caption&#8221;&gt;Find &#8220;INDIA&#8221; Game Rules &lt;/li&gt;<br />
&lt;li&gt;You can drag and drop any boxes. &lt;/li&gt;<br />
&lt;li&gt;We have set each letters from &#8220;INDIA&#8221; in the boxes. It is hidden&lt;/li&gt;<br />
&lt;li&gt;The game is, you need to find out the letters of &#8220;INDIA&#8221; by drag and drop the boxes to nearest box&lt;/li&gt;<br />
&lt;li&gt;Let us play the game now&#8230;&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>And we will set some styles to those elements.</p>
<p>[css]<br />
.dropDiv {<br />
border: 1px solid #ccc;<br />
width: 25%;<br />
height: auto;<br />
padding: 10px;<br />
display: inline;<br />
position: absolute;<br />
margin-left: 5px;<br />
min-height: 265px;<br />
}</p>
<p>.dragDiv {<br />
border: 1px solid #ccc;<br />
width: 27%;<br />
height: auto;<br />
padding: 10px;<br />
float: left;<br />
margin-left: 5px;<br />
min-height: 265px;<br />
}</p>
<p>#parent {<br />
/*border: 1px solid #ccc;*/<br />
height: 307px;<br />
width: 70%;<br />
padding: 20px;<br />
}</p>
<p>.droppable {<br />
width: 25px;<br />
height: 28px;<br />
padding: 5px;<br />
background-color: green;<br />
margin: 3px;<br />
float: left;<br />
cursor: move;<br />
}</p>
<p>.Notdroppable {<br />
width: 25px;<br />
height: 28px;<br />
padding: 5px;<br />
background-color: red;<br />
margin: 3px;<br />
float: left;<br />
}</p>
<p>#countdiv {<br />
margin-top: 10px;<br />
float: left;<br />
}</p>
<p>#gamerules {<br />
border: 1px solid #ccc;<br />
width: 250px;<br />
height: 280px;<br />
padding: 5px;<br />
float: right;<br />
margin-left: 5px;<br />
}</p>
<p>.caption {<br />
list-style: none;<br />
color: green;<br />
padding: 5px;<br />
font-weight: bold;<br />
}<br />
[/css]</p>
<p>So our page will look like as follows.</p>
<div id="attachment_9971" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag-And-Drop-Game12-e1440056905942.png"><img decoding="async" aria-describedby="caption-attachment-9971" class="size-full wp-image-9971" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag-And-Drop-Game12-e1440056905942.png" alt="Drag And Drop Game" width="650" height="363" srcset="/wp-content/uploads/2015/08/Drag-And-Drop-Game12-e1440056905942.png 650w, /wp-content/uploads/2015/08/Drag-And-Drop-Game12-e1440056905942-300x168.png 300w, /wp-content/uploads/2015/08/Drag-And-Drop-Game12-e1440056905942-400x223.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-9971" class="wp-caption-text">Drag And Drop Game</p></div>
<p>The next thing what we need to do is adding sortable functionality using <em>jquery sortable</em> to the div which has class as dropDiv.</p>
<p>[js]<br />
$(&#8220;.dropDiv&#8221;).sortable({<br />
connectWith: &#8216;.dropDiv&#8217;,<br />
forcePlaceholderSize: true,<br />
forceHelperSize: true,<br />
opacity: 0.60,<br />
placeholder: &#8216;placeholder&#8217;,<br />
tolerance: &#8216;touch&#8217;,<br />
scroll: false,<br />
cancel: &#8216;.dropDiv&#8217;,<br />
start: function (event, ui) {<br />
},<br />
stop: function (event, ui) {<br />
},<br />
update: function (event, ui) {<br />
},<br />
receive: function (event, ui) {<br />
}<br />
});<br />
[/js]</p>
<p>Please be noted that we have given connectWith property as follows to make the drag able div to be dropped only in the div which has class as dropDiv.</p>
<p>[js]<br />
connectWith: &#8216;.dropDiv&#8217;<br />
[/js]</p>
<p>We have also set the property cancel as follows to make the dropped div not drag able from dropDiv.</p>
<p>[js]<br />
cancel: &#8216;.dropDiv&#8217;,<br />
[/js]</p>
<p>Next we will set draggable for our inner divs.</p>
<p>[js]<br />
$(&#8216;.Notdroppable,.droppable&#8217;).draggable({<br />
connectToSortable: &#8216;.dropDiv&#8217;,<br />
containment: &#8220;#dropDiv&#8221;,<br />
helper: &#8216;clone&#8217;,<br />
revert: &#8216;invalid&#8217;<br />
});<br />
[/js]</p>
<h3><strong>Game Insights</strong></h3>
<p>As you can see in the html of the our dragDiv, we have set an attribute <em>myval</em> for some of the div. So what we are going to do is when a user drags a div we will check whether that particular div has that attribute and if it has, user got one letter. In this way user needs to collect 5 letters from the dragDiv.</p>
<p>So in the <em>stop</em> function of sortable we will write some scripts as follows.</p>
<p>[js]<br />
stop: function (event, ui) {<br />
++count;<br />
if (ui.item.attr(&#8216;myval&#8217;)) {<br />
$(&#8216;#draggedContent&#8217;).show().append(ui.item.attr(&#8216;myval&#8217;));<br />
}<br />
$(&#8220;.dragDiv div[myid=&#8221; + ui.item.attr(&#8216;myid&#8217;) + &#8220;]&#8221;).remove();<br />
var res = maxTrial &#8211; count;<br />
if (res == 0) {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;Sorry, you have no more chances left!!!. Please refresh to start the game again&#8217;);<br />
$(&#8216;.dragDiv .droppable, .dragDiv .Notdroppable&#8217;).remove();<br />
} else {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;You still have &#8216; + res + &#8216; tries&#8217;);<br />
}<br />
$(&#8216;.dropDiv .droppable, .dropDiv .Notdroppable&#8217;).remove();<br />
if ($(&#8216;#draggedContent&#8217;).html().length == 5) {<br />
alert(&#8216;You have won the game!!!. Please collect the prize from somewhere ;)&#8217;);<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;You have won the game!!!. Please collect the prize from somewhere ;)!. Please refresh to start the game again&#8217;);<br />
$(&#8216;.dragDiv .droppable, .dragDiv .Notdroppable&#8217;).remove();<br />
}</p>
<p>}<br />
[/js]</p>
<p>We are <a href="http://sibeeshpassion.com/find-an-inner-div-which-has-a-particular-attribute-and-remove/" target="_blank" rel="noopener">checking whether the inner div has a particular attribute</a> as follows and once we find it, we are removing that from dragDiv.</p>
<p>[js]<br />
if (ui.item.attr(&#8216;myval&#8217;)) {<br />
$(&#8216;#draggedContent&#8217;).show().append(ui.item.attr(&#8216;myval&#8217;));<br />
}<br />
$(&#8220;.dragDiv div[myid=&#8221; + ui.item.attr(&#8216;myid&#8217;) + &#8220;]&#8221;).remove();<br />
[/js]</p>
<p>If a user has already got those five letters, we must alert the user right? We will do this validation in <em>stop </em>function.</p>
<p>[js]<br />
start: function (event, ui) {<br />
if (count &gt; maxTrial) {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;Sorry, you have no more chances left!!!. Please refresh to start the game again&#8217;);<br />
} else {</p>
<p>}<br />
}<br />
[/js]</p>
<div id="attachment_9981" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game21-e1440063746818.png"><img decoding="async" aria-describedby="caption-attachment-9981" class="size-full wp-image-9981" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game21-e1440063746818.png" alt="Drag And Drop Game" width="650" height="241" srcset="/wp-content/uploads/2015/08/Drag_And_Drop_Game21-e1440063746818.png 650w, /wp-content/uploads/2015/08/Drag_And_Drop_Game21-e1440063746818-300x111.png 300w, /wp-content/uploads/2015/08/Drag_And_Drop_Game21-e1440063746818-400x148.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-9981" class="wp-caption-text">Drag And Drop Game</p></div>
<div id="attachment_9982" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game3-e1440063789835.png"><img decoding="async" aria-describedby="caption-attachment-9982" class="size-full wp-image-9982" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game3-e1440063789835.png" alt="Drag And Drop Game" width="650" height="215" srcset="/wp-content/uploads/2015/08/Drag_And_Drop_Game3-e1440063789835.png 650w, /wp-content/uploads/2015/08/Drag_And_Drop_Game3-e1440063789835-300x99.png 300w, /wp-content/uploads/2015/08/Drag_And_Drop_Game3-e1440063789835-400x132.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-9982" class="wp-caption-text">Drag And Drop Game</p></div>
<p>If there is no chances left, user will get a message as follows.</p>
<div id="attachment_9991" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game4-e1440063972976.png"><img decoding="async" aria-describedby="caption-attachment-9991" class="size-full wp-image-9991" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game4-e1440063972976.png" alt="Drag And Drop Game" width="650" height="224" srcset="/wp-content/uploads/2015/08/Drag_And_Drop_Game4-e1440063972976.png 650w, /wp-content/uploads/2015/08/Drag_And_Drop_Game4-e1440063972976-300x103.png 300w, /wp-content/uploads/2015/08/Drag_And_Drop_Game4-e1440063972976-400x138.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-9991" class="wp-caption-text">Drag And Drop Game</p></div>
<p>Now what we need to do next? Yes we need to shuffle div contents or elese user may find it easy when the tiles are in same order and in same place.</p>
<p><a href="http://sibeeshpassion.com/shuffle-div-contents/" target="_blank" rel="noopener">To shuffle the divs dynamically</a> we will add some scripts as follows.</p>
<p>[js]<br />
var parent = $(&#8220;#dragDivInner&#8221;);<br />
var divs = parent.children();<br />
while (divs.length) {<br />
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);<br />
}<br />
[/js]</p>
<p>Next we will <a href="http://sibeeshpassion.com/how-to-disable-right-click-in-a-page-using-jquery/" target="_blank" rel="noopener">disable the right click and mouse events</a> as follows.</p>
<p>[js]<br />
document.onmousedown = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
document.onkeydown = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
$(document).on(&#8220;contextmenu&#8221;, function (e) {<br />
return false;<br />
});<br />
[/js]</p>
<p>We will also <a href="http://sibeeshpassion.com/how-to-disable-f12-key-in-a-page-using-jquery/" target="_blank" rel="noopener">disable the F12 key of keyboard</a>.</p>
<p>[js]<br />
document.onkeypress = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
[/js]</p>
<p>As every game has some settings, we will also give some settings.</p>
<p>[html]<br />
&lt;div id=&#8221;gameSettings&#8221;&gt;<br />
&lt;br /&gt;<br />
Select Game Level :<br />
&lt;select id=&#8221;selectGameLevel&#8221;&gt;<br />
&lt;option value=&#8221;Easy&#8221;&gt;Easy&lt;/option&gt;<br />
&lt;option value=&#8221;Medium&#8221;&gt;Medium&lt;/option&gt;<br />
&lt;option value=&#8221;Hard&#8221;&gt;Hard&lt;/option&gt;<br />
&lt;/select&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>And in the drop down option change we will decrease the maximum trials allowed.</p>
<p>[js]<br />
$(&#8220;#selectGameLevel&#8221;).change(function (e) {<br />
var selected = $(&#8220;#selectGameLevel option:selected&#8221;).val();<br />
if (selected == &#8220;Easy&#8221;) {<br />
maxTrial = 25;<br />
} else if (selected == &#8220;Medium&#8221;) {<br />
maxTrial = 15;<br />
} else if (selected == &#8220;Hard&#8221;) {<br />
maxTrial = 10;<br />
}<br />
});<br />
[/js]</p>
<p>So our complete page will look like this.</p>
<div id="attachment_10001" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game5-e1440065282400.png"><img decoding="async" aria-describedby="caption-attachment-10001" class="size-large wp-image-10001" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Drag_And_Drop_Game5-1024x549.png" alt="Drag And Drop Game" width="634" height="340" /></a><p id="caption-attachment-10001" class="wp-caption-text">Drag And Drop Game</p></div>
<p>Our complete code is as follows.</p>
<h3><strong>Complete Code</strong></h3>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Find INDIA Game &#8211; Sibeesh Passion&lt;/title&gt;<br />
&lt;script src=&#8221;jquery-2.0.2.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;jquery-ui.js&#8221;&gt;&lt;/script&gt;<br />
&lt;style&gt;<br />
#body {<br />
background: url(&#8220;http://sibeeshpassion.com/content/images/indian%20flag%20banner.jpg&#8221;) no-repeat center center fixed;<br />
-webkit-background-size: cover;<br />
-moz-background-size: cover;<br />
-o-background-size: cover;<br />
background-size: cover;<br />
}</p>
<p>.dropDiv {<br />
border: 1px solid #ccc;<br />
width: 25%;<br />
height: auto;<br />
padding: 10px;<br />
display: inline;<br />
position: absolute;<br />
margin-left: 5px;<br />
min-height: 265px;<br />
}</p>
<p>.dragDiv {<br />
border: 1px solid #ccc;<br />
width: 27%;<br />
height: auto;<br />
padding: 10px;<br />
float: left;<br />
margin-left: 5px;<br />
min-height: 265px;<br />
}</p>
<p>#parent {<br />
/*border: 1px solid #ccc;*/<br />
height: 307px;<br />
width: 70%;<br />
padding: 20px;<br />
}</p>
<p>.droppable {<br />
width: 25px;<br />
height: 28px;<br />
padding: 5px;<br />
background-color: green;<br />
margin: 3px;<br />
float: left;<br />
cursor: move;<br />
}</p>
<p>.Notdroppable {<br />
width: 25px;<br />
height: 28px;<br />
padding: 5px;<br />
background-color: red;<br />
margin: 3px;<br />
float: left;<br />
}</p>
<p>#countdiv {<br />
margin-top: 10px;<br />
float: left;<br />
}</p>
<p>#gamerules {<br />
border: 1px solid #ccc;<br />
width: 250px;<br />
height: 280px;<br />
padding: 5px;<br />
float: right;<br />
margin-left: 5px;<br />
}</p>
<p>.caption {<br />
list-style: none;<br />
color: green;<br />
padding: 5px;<br />
font-weight: bold;<br />
}</p>
<p>#gameSettings {<br />
width: auto;<br />
}<br />
&lt;/style&gt;<br />
&lt;script&gt;<br />
var count = 0;<br />
var maxTrial = 25;<br />
document.onkeypress = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
document.onmousedown = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
document.onkeydown = function (event) {<br />
event = (event || window.event);<br />
if (event.keyCode == 123) {<br />
return false;<br />
}<br />
}<br />
$(function () {<br />
$(document).on(&#8220;contextmenu&#8221;, function (e) {<br />
return false;<br />
});<br />
var parent = $(&#8220;#dragDivInner&#8221;);<br />
var divs = parent.children();<br />
while (divs.length) {<br />
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);<br />
}<br />
$(&#8220;#selectGameLevel&#8221;).change(function (e) {<br />
var selected = $(&#8220;#selectGameLevel option:selected&#8221;).val();<br />
if (selected == &#8220;Easy&#8221;) {<br />
maxTrial = 25;<br />
} else if (selected == &#8220;Medium&#8221;) {<br />
maxTrial = 15;<br />
} else if (selected == &#8220;Hard&#8221;) {<br />
maxTrial = 10;<br />
}<br />
});<br />
$(&#8216;.Notdroppable,.droppable&#8217;).draggable({<br />
connectToSortable: &#8216;.dropDiv&#8217;,<br />
containment: &#8220;#dropDiv&#8221;,<br />
helper: &#8216;clone&#8217;,<br />
revert: &#8216;invalid&#8217;<br />
});<br />
$(&#8220;.dropDiv&#8221;).sortable({<br />
connectWith: &#8216;.dropDiv&#8217;,<br />
forcePlaceholderSize: true,<br />
forceHelperSize: true,<br />
opacity: 0.60,<br />
placeholder: &#8216;placeholder&#8217;,<br />
tolerance: &#8216;touch&#8217;,<br />
scroll: false,<br />
cancel: &#8216;.dropDiv&#8217;,<br />
start: function (event, ui) {<br />
if (count &gt; maxTrial) {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;Sorry, you have no more chances left!!!. Please refresh to start the game again&#8217;);<br />
} else {</p>
<p>}<br />
},<br />
stop: function (event, ui) {<br />
++count;<br />
if (ui.item.attr(&#8216;myval&#8217;)) {<br />
$(&#8216;#draggedContent&#8217;).show().append(ui.item.attr(&#8216;myval&#8217;));<br />
}<br />
$(&#8220;.dragDiv div[myid=&#8221; + ui.item.attr(&#8216;myid&#8217;) + &#8220;]&#8221;).remove();<br />
var res = maxTrial &#8211; count;<br />
if (res == 0) {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;Sorry, you have no more chances left!!!. Please refresh to start the game again&#8217;);<br />
$(&#8216;.dragDiv .droppable, .dragDiv .Notdroppable&#8217;).remove();<br />
} else {<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;You still have &#8216; + res + &#8216; tries&#8217;);<br />
}<br />
$(&#8216;.dropDiv .droppable, .dropDiv .Notdroppable&#8217;).remove();<br />
if ($(&#8216;#draggedContent&#8217;).html().length == 5) {<br />
alert(&#8216;You have won the game!!!. Please collect the prize from somewhere ;)&#8217;);<br />
$(&#8216;#countdiv&#8217;).show().html(&#8216;You have won the game!!!. Please collect the prize from somewhere ;)!. Please refresh to start the game again&#8217;);<br />
$(&#8216;.dragDiv .droppable, .dragDiv .Notdroppable&#8217;).remove();<br />
}</p>
<p>},<br />
update: function (event, ui) {<br />
},<br />
receive: function (event, ui) {<br />
}<br />
});<br />
});<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body id=&#8221;body&#8221;&gt;<br />
&lt;div id=&#8221;gameSettings&#8221;&gt;<br />
&lt;br /&gt;<br />
Select Game Level :<br />
&lt;select id=&#8221;selectGameLevel&#8221;&gt;<br />
&lt;option value=&#8221;Easy&#8221;&gt;Easy&lt;/option&gt;<br />
&lt;option value=&#8221;Medium&#8221;&gt;Medium&lt;/option&gt;<br />
&lt;option value=&#8221;Hard&#8221;&gt;Hard&lt;/option&gt;<br />
&lt;/select&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;parent&#8221; style=&#8221;float: left;&#8221;&gt;<br />
&lt;div class=&#8221;dragDiv&#8221;&gt;<br />
&lt;div id=&#8221;dragDivInner&#8221;&gt;<br />
&lt;div myid=&#8221;1&#8243; class=&#8221;droppable&#8221; myval=&#8221;I&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;2&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;3&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;6&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;7&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;8&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;9&#8243; class=&#8221;droppable&#8221; myval=&#8221;N&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;10&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;11&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;12&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;17&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;18&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;19&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;20&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;A&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;21&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;22&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;23&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;24&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;25&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;I&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;26&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;27&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;28&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;29&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;30&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;31&#8243; class=&#8221;Notdroppable&#8221; myval=&#8221;D&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;32&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;33&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;34&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;35&#8243; class=&#8221;droppable&#8221;&gt;&lt;/div&gt;<br />
&lt;div myid=&#8221;40&#8243; class=&#8221;Notdroppable&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;countdiv&#8221; style=&#8221;display: none;&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div class=&#8221;dropDiv&#8221;&gt;<br />
&lt;div id=&#8221;draggedContent&#8221; style=&#8221;display: none;&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;gamerules&#8221;&gt;<br />
&lt;ul&gt;<br />
&lt;li class=&#8221;caption&#8221;&gt;Find &#8220;INDIA&#8221; Game Rules &lt;/li&gt;<br />
&lt;li&gt;You can drag and drop any boxes. &lt;/li&gt;<br />
&lt;li&gt;We have set each letters from &#8220;INDIA&#8221; in the boxes. It is hidden&lt;/li&gt;<br />
&lt;li&gt;The game is, you need to find out the letters of &#8220;INDIA&#8221; by drag and drop the boxes to nearest box&lt;/li&gt;<br />
&lt;li&gt;Let us play the game now&#8230;&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<h2><span id="conclusion">Conclusion</span></h2>
<p>Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></h2>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/a-drag-and-drop-game/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
