What is Jquery?

JQuery is Java Script library or Java Script Framework which helps in how to traverse HTML documents, do some cool animations, and add Ajax interaction to any web page. It mainly helps programmer to reduce lines of code as huge code written in Java Script, can be done easily with JQuery in few lines.

For detailed information, check below link.
http://bit.ly/v0QdsH

Click below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

What does dollar Sign ($) means in JQuery?

Dollar Sign is nothing but it’s an alias for JQuery. Take a look at below jQuery code

$(document).ready(function(){

});

Over here $ sign can be replaced with “jQuery ” keyword.

jQuery(document).ready(function(){

});

Click below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

How is body onload() function is different from document.ready() function used in jQuery?

Document.ready() function is different from body onload() function because off 2 reasons.1. We can have more than one document.ready() function in a page where we can have only one onload function.
2. Document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.

Click below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

What are the steps you need to follow to use jQuery in ASP.Net project?

It’s really simple. One just need to add reference of javascript file(.js). Go to Jquery.com and download the latest version of jQuery. When download is completed, there is a “jQuery-1.3.2.js” in the folder. Include this file

<script src="_scripts/jQuery-1.3.2.js" type="text/javascript"></script>

and you good to go now for JQuery.

Note : 1.3.2 denotes the library version.. It can be vary depending upon the version of Jquery you download.

Click below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

What is JQuery UI?

JQuery UI is a library which is built on top of JQuery library. JQuery UI comes with cool widgets, effects and interaction mechanism.See below page on this site. Date Picker control used in this page to select date is an example of JQuery UI.

http://www.dotnetfunda.com/misc/topperformers.aspx

Click below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

What are features of JQuery or what can be done using JQuery?

Features of Jquery
1. One can easily provide effects and can do animations.
2. Applying / Changing CSS.
3. Cool plugins.
4. Ajax support
5. DOM selection events
6. Event HandlingClick below link to get mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html

Name some of the methods of JQuery used to provide effects?

Some of the common methods are :1. Show()
2. Hide()
3. Toggle()
4. FadeIn()
5. FadeOut()

Visit my blog.
http://jquerybyexample.blogspot.com/

JQuery is replacement of Java Script?

NOTE: This is objective type question, Please click question title for correct answer.

What are the different type of selectors in Jquery?

There are 3 types of selectors in Jquery
1. CSS Selector
2. XPath Selector
3. Custom SelectorVisit my blog.
http://jquerybyexample.blogspot.com/

What are the advantages of JQuery ?

There are many advantages with JQuery. Some of them are :

. It is more like a JavaScript enhancement so there is no overhead in learning a new syntax.

. It has the ability to keep the code simple, readable, clear and reusable.

. It would eradicate the requirement for writing complex loops and DOM scripting library calls.

How can you select all elements in a page using jQuery?

To select all elements in a page, we can use all selectors, for that we need to use *(asterisk symbol).

<script language="javascript" type="text/javascript">

         $("*").css("border", "2px dotted red"); 

</script>

The above code will select all elements of the web page and apply border width as 2 pixel, style as dotted and color as red.

Thanks and Regards
Akiii

What is jQuery?

jQuery is not a language but it is a well written JavaScript code, As quoted on official jQuery website “it is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.“In order to work with jQuery you should be aware of basics of JavaScript, HTML and CSS.
It was released in January 2006 at BarCamp NYC by John Resig.

Licensing:
It is free, open source software Dual-licensed under the MIT License and the GNU General Public License. Microsoft has integrated jQuery officially into its IDE Visual Studio 2010 and jQuery intellisense is available in Visual Studio 2010 now.

Why jQuery?

jQuery is very compact and well written JavaScript code that increases the productivity of the developer by enabling them to achieve critical UI functionality by writing very less amount of code.It helps to

# Improve the performance of the application
# Develop most browser compatible web page
# Implement UI related critical functionality without writing hundreds of lines of codes
# Fast
# Extensible – jQuery can be extended to implement customized behavior

Other advantages of jQuery are

# No need to learn fresh new syntax’s to use jQuery, knowing simple JavaScript syntax is enough
# Simple and Cleaner code, no need to write several lines of codes to achieve complex functionality.

Where to download jQuery from?

jQuery javascript file can be downloaded from jQuery Official websitehttp://www.jquery.com/

How to use jQuery?

jQuery usually comes as a single JavaScript file containing everything comes out of the box with jQuery. It can be included within a web page using the following mark-up:To load local jQuery file

<script type="text/javascript" src="jQuery-1.4.1-min.js"></script>

Ideally this markup is kept in under <head></head> tag of your web page, however you are free to keep anywhere you want.

Do I need to refer jQuery file both in Master page/base page/template page and content page?

No, master page/base page/ template page basically helps to create consistent layout for the page in the application. In case you have referred the jQuery file in master page/base page/ template page that cause rendering the file in the browser, you do not need to refer jQuery file the content page again.In summary, there should not be more than one <script> tag with jQuery file reference in the source code of the rendered web page in the browser.

What is the difference between jQuery-x.x.x.js and jQuery.x.x.x-min.js

In terms of functionality, there is no difference between the jQuery-x.x.x.js and jQuery-x.x.x-min.js (also called minified version). However this can play a vital role in the performance of the web page.How it affects the performance?
jQuery-1.4.4.js file size is 178 KB as against its minified version jQuery-1.4.4-min.js that is only 76.7 KB in size. So when your page loads in the client?s browser if you are not using minified version, it loads 178 KB file that takes more time to load than 76.7 KB.

Which version of jQuery file should be used?

In most of the recent releases so far, the core functionality of jQuery remains same however some more cool and better features are added. Ideally you should use the latest jQuery files available on the jQuery.com website. By doing this you ensure that your earlier functionality will still work and you can use new features available as part of the new release.

What is CDN?

CDN Stands for Content Distribution Network or also called Content Delivery Network is a group of computers placed at various points connected with network containing copies of data files to maximize bandwidth in accessing the data. In CDN a client access a copy of data nearer to the client location rather than all clients accessing
from the one particular server. This helps to achieve better performance of data retrieval by client.There are two leading CDNs available that hosts jQuery files.

Microsoft – To load jQuery from Microsoft AJAX CDN
jQuery file can be loaded from Microsoft AJAX CDN. For more details, go to http://www.asp.net/ajaxlibrary/cdn.ashx. You will need to keep following tags in your page.

<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>

Google – To load jQuery from Google Libraries API

jQuery file can be loaded from Google CDN for more details, go to http://code.google.com/apis/libraries/devguide.html. You will need to keep following tag in your page.

<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

Why to load jQuery file from CDN?

You may ask that if we can load the jQuery file from our own server why to load it from the CDNs. The answer is logical and very simple. The browser behavior is that whenever it loads any webpage, it keeps related files (eg. Javascript file, CSS file and Images) used for that page into its cache (also called history). When next time the user browses any web page, browser loads only those files that are new or modified and is not available in the browser cache or history. In this way, browser improves its performance and loads the page.

The possibility is that if more and more websites are using CDNs, the user might have already browsed some other web pages that is using CDNs jQuery file and that file may have into browser cache; so when user browse your page and you are also using CDNs file, the older cached version of jQuery file will be used. In this way your page will load faster as browser will not have to load the jQuery file for your page again.

The benefit
1. Faster page load as jQuery file need not to be downloaded
2. Saves your bandwidth as jQuery file is not loaded from your server
3. Scalable – generally CDNs place these files on the servers located at different geographical locations of the world so that they load faster so irrespective of from where your user is browsing your page, your application runs well.

What if the latest jQuery version is available and I am still referring older version of jQuery file from CDNs?

Do not worry about it, it?s a general promise made by CDNs that they will remain hosting the older version of the files on the same location where they had initially released; so even if newer version of the files are released, the older version remains there on the CDNs and your web page still works.

How to load local jQuery file in case CDN is not available?

Sometimes, it may happen that the CDN you have used to load the jQuery file is not available (it rarely happens, however anything is possible, isn?t it?); in that case you should load your local jQuery file that is available on your server so that all jQuery related functionality still work on your page.Write following lines of code

<!– START – jQuery Reference –>

<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js "></script>

<script type='text/javascript'>//<![CDATA[

if (typeof jQuery == 'undefined') {

document.write(unescape("%3Cscript src='/Script/jquery-1.4.1.min.js' type='text/javascript' %3E%3C/script%3E"));

}//]]>

</script>

<!– END – jQuery Reference –>

Replace bolded path with your own jQuery file path on the server. In the above code, first line tries to load the jQuery file from CDN, if browser could load the file successfully, “jQuery” variable will not be undefined and next script will not run otherwise next script will run that will write the script tag to load the jQuery file from your server.

How to execute jQuery code?

1. As and when page loads, execute the jQuery code

 <script language="javascript" type="text/javascript">

           $(function () {

           $("#div1").css("border", "2px solid green");

            });

            </script>

OR

   <script language="javascript" type="text/javascript">

                     $("#div1").css("border", "2px solid green");

                </script>

The benefit of executing jQuery code in this way is that it doesn?t wait the whole page to load completely, so in case you want user to see the effects as soon as the corresponding elements are loaded, you can use this.

However the disadvantage is that if the element on which jQuery has to execute has not loaded then it will error out or you will not get desired result; so while using this way of executing jQuery code, you will have to make sure that the element on which you want to work with jQuery is loaded first (you can place your jQuery code right after your HTML element).

2. Execute jQuery only when the complete DOM objects (the complete page has been loaded). You will have to wrap your code in .ready function.

<script language="javascript" type="text/javascript">

               $(document).ready(function () {

                   $("#div1").css("border", "2px solid green");

   });

</script>

This is the better and safer way to execute jQuery. This makes sure that jQuery code will execute only if complete page has been loaded in the browser so you are rest assured that user will not see any undesired behavior on the page.

As a developer, the decision of where and how to write jQuery code lies on you. I prefer to use 2nd method as it ensures that my complete page is loaded in the browser and I am ready to play with any element available on the page.

jQuery Core

jQuery accepts a string enclosed with double quote (“”) that can contain a CSS selector which is used to match a set of elements on the web page.jQuery code can start with either “jQuery” word or a “$” (dollar symbol). Take a look at below code snippet

<script language="javascript" type="text/javascript">

                  $(function () {

                       jQuery("#div1").css("border", "2px solid red");

                       });

</script>

OR

<script language="javascript" type="text/javascript">

          $(function () {

                  $("#div1").css("border", "2px solid green");

           });

</script>

Both above code snippets are functionally same and do the same thing. So you can either user jQuery or $ when you are writing jQuery code.

How to give alert message in jQuery on a Button Click ?

Hi all,
First, include jQuery in your application.Drop a textbox in your .aspx page:-

<input id="inputField" type="text" size="12"/>

include a button also:-

<asp:Button ID="Button1" runat="server" Text="get"/>

Now, here’s the script:-

<script type="text/javascript">

        $(document).ready(function () {

            $('#Button1').click(function () {

                alert($('#inputField').attr("value"));

            });

        });

</script>

On the click of the button, an alert will be given containing the text in the text box.

I hope this helps……
Thanks and Regards
Akiii

What are Selectors in jQuery mean ?

Generally in HTML, if we need to work with any control on a web page we need to find the control. For that we use document.getElementByID or document.getElementByName. But in jquery we do it using Selectors.Using this selectors we can select all the controls as well using a symbol (* )

A sample code snippet can be of this form

<script language="javascript" type="text/javascript">

$("*").css("border", "10px red");

</script>

This will make all the borders in the web page with a width of 10 pixel and color as red.

Is it good to load jquery from CDN(Content delivery network) ?

Yes, it is always good to load your jquery from content delivery network. It provides some benefits like :-
(1) Caching – It means that if any previously visited site by user is using jQuery from Google CDN then the cached version will be used. It will not be downloaded again.
(2) Reduces load – It reduces the load on your web server as it downloads from Google server’s.Example :-

<script  type="text/javascript"

    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">

</script>

Thanks and Regards
Akiii

Do we need to add the JQuery file both at the Master page and Content page as well?

No, if the Jquery file has been added to the master page then we can access the content page directly without adding any reference to it.This can be done using this simple example

<script type="text/javascript" src="jQuery-1.4.1-min.js"></script>

What is the advantage of using the minified version of JQuery rather than using the conventional one?

The advantage of using a minified version of JQuery file is Efficiency of the web page increases.The normal version jQuery-x.x.x.js has a file size of 178KB

but the minified version jQuery.x.x.x-min.js has 76.7 KB.

The reduction in size makes the page to load more faster than you use a conventional jQuery file with 178KB

What is CDN and how jQuery is related to it?

CDN – It stands for Content Distribution Network or Content Delivery Network.Generally, a group of systems at various places connected to transfer data files between them to increase its bandwidth while accessing data. The typical architecture is designed in such a way that a client access a file copy from its nearest client rather than accessing it from a centralized server.

So we can load this jQuery file from that CDN so that the efficiency of all the clients working under that network will be increased.

Example :

We can load jQuery from Google libraries API

<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

Can we select a element having a specific class in jQuery ?

Yes, we can select an element with a specific class, we use the class selector.The class name must contain the prefix as “.” (dot).

<script language="javascript" type="text/javascript">

         $(".class1").css("border", "2px solid red");

</script>

Above code will select all the elements of the webpage containing the class as “class1” and apply the css style border width as 2 Pixel, style as solid and color as red.

What is the use of Delegate() Method in jQuery?

The delegate() method can be used in two ways.
1) If you have a parent element, and you want to attach an event to each one of its child elements, this delegate() method is used.
Ex:Un-ordered List
Instead of attaching an event to each <li> element, you can attach a single event to <ul> element.Example:

$("ul").delegate("li", "click", function(){

$(this).hide();

});

2) When an element is not available on the current page, this method is used.
.live() method is also used for the same purpose but, delegate() method is a bit faster.

Example:

$("ul").delegate("li", "click", function(){

$(this).hide();

});

This will hide any list items that are not currently available on the page. They may be loaded via an Ajax request and then append to it.
Using .bind() or .click() methods, you would have to manually attach events to these new list items once they are added.

Which sign does jQuery use as a shortcut for jQuery?

NOTE: This is objective type question, Please click question title for correct answer.

JQuery is a client scripting.

NOTE: This is objective type question, Please click question title for correct answer.

Can be used JQuery with AJAX?

NOTE: This is objective type question, Please click question title for correct answer.

JQuery is JavaScript Library or JSON Library?

JQuery is a javascript library not JSON Library. Jquery library is single JavaScript file that contains Common DOM, event effects and Ajax functions.”JQuery is a library of javascript function.”

For more Info: http://jquery.com/

What does .size() method of jquery return ?

.size() method of jquery returns number of element in the object. That means that you can count the number of elements within an object.For example :-

$(document).ready(function(){ 

 var Count = $("div").size();

 alert(Count);

});

Thanks and Regards
Akiii

What is the difference between jquery.size() and jquery.length ?

jquery.size() and jquery.length both returns the number of element found in the object. But, jquery.length is faster than jquery.size() because size() is a method but length is a property .So, there is always an overhead in calling a function.

Thanks and Regards
Akiii

How to set Page Title using jQuery ?

$(function(){

   $(document).attr("title", "Dotnet Funda");

});

Thanks and Regards
Akiii

How will you Encode/Decode URL in jQuery ?

In jquery, you can use the following functions to encode and decode url :-

encodeURIComponent(url) and decodeURIComponent(url)

You have to pass the complete url with parameterized value in the function and in return it will encode/decode you url for you !

What is the use of jQuery Connect?

It is used to connect or bind a function to another function.It is use to execute a function whenever
a function from another object is executed.e.g.

function FirstFunction(){ 

this.Func1 = function(){ 

       execute1 = 'A class'; 

      } 

} 

var firstFunc = new FirstFunction();

function SecondFunction(){ 

 this.Func2 = function(){ 

 execute2 = 'Another Class'; 

 } 

} 

var secondFunc = new SecondFunction(); 

$.connect(firstFunc,'Func1',secondFunc,Func2);

In this case whevever we invoke secondFunc.Func2,firstFunc.Func1 will also gets executed indicating that
Func2 of object secondFunc has been associated/ connected to Func1 of object firstFunc

What is the use of jQuery disconnect?

It is used to disconnect a function to another function.It is the opposite of $.connect.e.g.

$.disconnect(firstFunc,'Func1',secondFunc,Func2);

will disconnect Func1 from Func2 where Func1 is the reference function and Func2 is connected one.

What is the use of jQuery disconnectAll?

It is used to disconnect all the connected functions.e.g.

$.disconnectAll(firstFunc,'Func1');

will disconnect all the connected function from the reference function Func1.

What are the minimal/must steps needed to execute JQuery?

1.Wait for the DOM of the page to be ready.
2.Finds the appropriate HTML elements that needs to be acted on by using selector.
3.Add event handlers.e.g.

//Step 1: Wait for the DOM of the page to be ready. 

$(document).ready(function () 

{

	//Step 2: Finds the appropriate HTML elements that needs to be acted on by using selector

	var btnObject = $('#btnSayHello'); 

	//Step 3: Add event handlers (Here click events)

	btnObject.click(function () 

	{

		alert("Hello World...My First JQuery Program");

	});

});

How to debug JQuery?

1.Placing debugger keywordAdd the keyword debugger to the line from where we want to start the debugging and then run the Visual Studio in Debug mode by pressing F5 or using the Debug button.

e.g.

<script language ="javascript">

$(document).ready(function () 

{

   var btnObject = $('#btnSayHello');

   debugger;

    btnObject.click(function ()

   {

       alert("Hello World...My First JQuery Program");

   });

});

</script>

2.Inserting a break point after attaching worker process

Press ALT + CTRL + P or tools -> AttachProcess then choose w3wp.exe .

What are the ways by which we can include JQuery in our page?

1.Refer to a local copy using the <script> tag
2.Refer to a remote copy on JQuery.com or the remote copy in the Google AJAX API
3.Refer to a local copy using Script Manager Control
4.Refer to an embedded script using the ClientScript object

How to invoke Jquery function from code behind?

Suppose we want to change the background color of a div tag from the code behind upon button click.In code behind write the below

protected void btnChangecolor_Click(object sender, EventArgs e) 

{ 

string script = "<script type=\"text/JavaScript\" language=\"javascript\">ChangeDivBackgroundcolor();</script>";

 Page.ClientScript.RegisterStartupScript(this.GetType(), "ChangeColor", script); 

 }

The aspx file will be as under

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 

<title></title> 

<script type="text/javascript" src="Scripts/jquery-1.7.2.js"></script> 

<script type="text/javascript"> 

function ChangeDivBackgroundcolor() 

{ 

var divObject = $('#divTest'); 

divObject.css("background-color", "cyan"); 

} 

</script> 

</head> 

<body> 

<form id="form1" runat="server"> 

<div> 

<asp:Button ID="btnChangecolor" runat="server" Text="Say Hello" onclick="btnChangecolor_Click" />

 </div> 

<div id="divTest">Change the color of this div</div> 

</form> 

</body> 

</html>

What is the significance of document.ready()?

It indicates that the DOM of the page is ready and we can start manipulating the DOM elements even though other parts
of the page content(e.g. images/other external resources) are not fully loaded.As soon as the DOM is loaded,
everything inside the (document).ready() should be load even before the page contents are loaded.

Why is JQuery faster than Javascript at execution time?

The onLoad function for the window object executes after the entire page is fully loaded.Untill DOM tree is completely created and all images/other associated resources (like audio files,video files etc) are fully loaded,this onLoad function is never executed and hence the script execution needs to wait till the page is loaded.But the document.ready() method of JQuery indicates that the DOM of the page is ready and we can start manipulating the DOM elements even though other parts of the page content(e.g. images/other external resources) are not fully loaded.As soon as the DOM is loaded, everything inside the (document).ready() should be load even before the page contents are loaded.

It is because of this reason that JQuery code runs faster

Difference between jQuery-x.x.x.js and jQuery.x.x.x min.js?

In terms of functionality, there is no difference between the jQuery-x.x.x.js and jQuery-x.x.x-min.js .jQuery-x.x.x-min.js is also called as minified version of jQuery.jQuery-1.4.4.js file size is 178 KB and the jQuery-1.4.4-min.js size is 76.7 KB. If you are not using minified version of jQuery,then it will load the 178 kb file( jQuery-1.4.4.js).So it will take the much time to load the page and will hurt the performance.

So we can prefer using jQuery-1.4.4.js during development and jQuery-1.4.4-min.js when we move the code into production environment.

What is the purpose of jquery-x.x.x-vsdoc.js?

Generally we will use jQuery-x.x.x-vsdoc.js to provide the intellisense support. We can even delete this file. But the thing is that it won’t provide the intellisense support if we delete that file.

Which one is the right way to get the TextBox value with id=”txtbox” in Jquery?

NOTE: This is objective type question, Please click question title for correct answer.