What is Jquery?

jQuery is a JavaScript Library.

Which of the following is correct?

jQuery is a JavaScript Library
jQuery is a JSON Library

Answer :jQuery is a JavaScript Library

jQuery uses CSS selectors and XPath expressions to select elements?

False
True

Answer: True

Which sign does jQuery use as a shortcut for jQuery?

$ sign
% sign
? Sign

Answer: $ sign

Is jQuery a W3C standard?

Yes
No

Answer: NO

$(“span”). What does it select?

All span elements
The first span element

Answer: All span elements

Is jQuery a library for client scripting or server scripting?

Client scripting
Server scripting

Answer: Client scripting

Is it possible to use jQuery together with AJAX?

Yes
No

Answer: Yes

The jQuery html() method works for both HTML and XML documents

True
False

Answer :False

jQuery code to set the background color of all span elements to blue?

$(“span”).style(“background-color”,”blue”);
$(“span”).manipulate(“background-color”,”blue”);
$(“span”).css(“background-color”,”blue”);
$(“span”).layout(“background-color”,”blue”);

Answer: $(“span”).css(“background-color”,”blue”);

$(“span.intro”). What does it select?

The first span element with class=”intro”
The first span element with id=”intro”
All span elements with id=”intro”
All span elements with class=”intro”

Answer: All span elements with class=”intro”

jQuery method to hide selected elements?

visible(false)
hidden()
display(none)
hide()

Answer: hide()

jQuery method to set one or more style properties for selected elements?

style()
css()
html()

Answer: css()

jQuery method is used to perform an asynchronous HTTP request?

jQuery.ajaxAsync()
jQuery.ajaxSetup()
jQuery.ajax()

Answer: jQuery.ajax()

What scripting language is jQuery written in?

VBScript
C++
JavaScript
C#

Answer: JavaScript

$(“div#id1 .cl1”). What does it select?

The first element with id=”cl1″ inside any div element with class=”id1″
All elements with class=”cl1″ inside the first div element with id=”id1″
All div elements with id=”id1″ or

Answer: All elements with class=”cl1″ inside the first div element with id=”id1″

Difference between onload() and document.ready() function used in jQuery?

  • We can add more than one document.ready() function in a page.
  • we can have only one onload function.
  • Document.ready() function is called as soon as DOM is loaded.
  • body.onload() function is called when everything (DOM, images..)gets loaded on the page.

JQuery Methods used to provide effects?

1. Show()
2. Hide()
3. Toggle()
4. FadeIn()
5. FadeOut()

What are the different type of selectors in Jquery?

1. CSS Selector
2. XPath Selector
3. Custom Selector

What does .size() method of jquery return ?

.size() method of jquery returns number of element in the object.

 How do you get the text value?

$(“#textbox1”).val();

 How do you check or uncheck a checkbox input or radio button?

1.$(‘#num1’).attr(‘checked’, true);// Check #num1

2.$(‘#num1’).attr(‘checked’, false);// Uncheck #num1

3.$(“#num1”).attr(‘checked’, ‘checked’);// Check #num1

4.$(“#num1”).removeAttr(‘checked’);// Uncheck #num1

Ajax Request in Jquery

$.ajax({
url: ‘test.php’,
success: function(response) {
alert(response);
},
error: function(res) {
alert(res.status);
}
});

Explain the each() function.

$(“#num”).click(function(){
$(“li”).each(function(){
document.write($(this).text())
});
});

1) What do you need to do in order to use jQuery in your project?
Ans: We need to import the jQuery minified js and css files

2) What is the difference between normal and minimal version of .js files that are shipped with jQuery bundle?
Ans: The minified version is useful in production system because it saves the bandwidth and decreases page loading speed.

3) Can one download and change the jQuery base code and use it? Did you every feel like changing the code base for something that was missing in the bundle? Under what scenarios will you consider modifying the jQuery code base?
Ans: This should ideally never be required and we shall post the issue to jQuery library to the developer community.

4) Which version of jQuery have you worked on. What steps will you take to migrate your web application to the latest version of jQuery?
Ans: There are different versions for jQuery Mobile and jQuery normal libraries and discuss the version you have been using.

5) What all features of jQuery have you used in your web projects?
Ans: jQuery offers a lot of features like Accordian, Sliding menu, File upload etc.

6) Would you prefer using a feature available in jQuery than writing the same functionality using custom javascript and CSS?
Ans: It is better to use the same feature using jQuery than writing custom css and js.

7) What all browser related issues you have faced with jQuery?
Ans: Browser compatibility of jQuery plugins is an issue and needs lot of time and effort to fix.

8 ) What is the difference between javascript’s onload function invoked from HTML body tag like <body onload=”somefunction();”> and jQuery’s ready function?
Ans: We can have multiple onload handlers in jQuery but not with body tag.

9) On what parameters will you judge a jQuery plugin before using it in your application?
Ans:
1) Browser compatibility.
2) Performance.
3) Ease of use.

10) What all techniques have you been using in order to increase the performance of a web application developed using jQuery?
Ans: Try not add too many event handlers on load event. Use proper element selectors.

11) Given the option to decide on a Javascript framework for a JEE based web application, what other frameworks will you consider before making a choice?
Ans: There are many other food javascript frameworks including prototype, dojo and YUI.
Note: You may also want to browse through our dojo tutorial series.

12) What all jQuery plugins have you used? Explain them?

13) Can you write the code to send an Ajax request to a JSP page?
Ans: One can use $.POST() and $.GET() to issue Ajax requests in web applications.

14) Have you used overlay effect of jQuery? What configuration settings are available for creating the overlay effect?

15) Which jQuery editor do you use?
Ans: While there could be multiple plugins for IDE that add jQuery support but you shouldn’t fail to mention the big names likeAptana Studio IDE and less known jsdt-jquery.

Questions : 1 What is jQuery ?
Answers : 1 It’s very simple but most valuable Question on jQuery means jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, animating, event handling, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. Jquery is build library for javascript no need to write your own functions or script jquery all ready done for you
Questions : 2 How you will use Jquery means requirement needed for using jquery
Answers : 2 Nothing more need to do just olny download jquery library(.js file) from any of the jquery siteDownload jquery and just linked with your html pages like all other javascript filelike below :
< script src=”jquery.js” language=”javascript” type=”text/javascript”>
Questions : 3 what the use of $ symbol in Jquery
Answers : 3 $ Symbol is just replacement of jquery means at the place of $ you may use jquery hence $ symbol is used for indication that this line used for jquery
Questions : 4 How do you select an item using css class or ID and get the value by use of jquery
Answers : 4 If an element of html like < div> , < p> or any tag have ID MyId and class used MyClass then we select the element by below jquery code$(‘#MyId’) for ID and for classs $(‘.MyClass’) and for valuevar myValue = $(‘#MyId’).val(); // get the value in var Myvalue by id
Or for set the value in selected item

$(‘#MyId’).val(“print me”); // set the value of a form input

Questions : 5 How to get the server response from an AJAX request using Jquery?
Answers : 5 When invoking functions that have asynchronous behavior We must provide a callback function to capture the desired result. This is especially important with AJAX in the browser because when a remote request is made, it is indeterminate when the response will be received.Below an example of making an AJAX call and alerting the response (or error):

 $.ajax({
     url: 'pcdsEmpRecords.php',
     success: function(response) {
        alert(response);
     },
     error: function(xhr) {
        alert('Error!  Status = ' + xhr.status);
     }
 });
Questions : 6 How do you update ajax response with id ” resilts”
Answers : 6 By using below code we can update div content where id ‘results’ with ajax response

 function updateStatus() {
     $.ajax({
            url: 'pcdsEmpRecords.php',
            success: function(response) {
             // update div id Results 
             $('#results').html(response);
         }
     });
 }
Questions : 7 How do You disable or enable a form element?
Answers : 7 There are two ways to disable or enable form elements.Set the ‘disabled’ attribute to true or false:

 // Disable #pcds
 $('#pcds').attr('disabled', true);
 // Enable #pcds
 $('#pcds').attr('disabled', false);

Add or remove the ‘disabled’ attribute:

 // Disable #pcds
 $("#pcds").attr('disabled', 'disabled');
 // Enable #x
 $("#pcds").removeAttr('disabled');
Questions : 8 How do you check or uncheck a checkbox input or radio button?
Answers : 8 There are two ways to check or uncheck a checkbox or radio button.Set the ‘checked’ attribute to true or false.

 // Check #pcds
 $('#pcds').attr('checked', true);
 // Uncheck #pcds
 $('#pcds').attr('checked', false);

Add or remove the ‘checked’ attribute:

 // Check #pcds
 $("#pcds").attr('checked', 'checked');
 // Uncheck #pcds
 $("#pcds").removeAttr('checked');
Questions : 9 How do you get the text value of a selected option?
Answers : 9 Select elements typically have two values that you want to access. First there’s the value to be sent to the server, which is easy:

 $("#pcdsselect").val();
 // => 1

The second is the text value of the select. For example, using the following select box:

 <select id="pcdsselect">

   <option value="1">Mr</option>
   <option value="2">Mrs</option>
   <option value="3">Ms</option>
   <option value="4">Dr</option>

   <option value="5">Prof</option>
 </select>

If you wanted to get the string “Mr” if the first option was selected (instead of just “1”), you would do that in the following way:

 $("#mpcdsselect option:selected").text();
 // => "Mr"



1).What is Jquery?
 jquery is javascript library which required a jquery.js file. After that you can write the jquery as fallows. It uses "$" as the short hand to write jquery code.
 Simple Syntax is
Code:
$(document).ready(function()
{
function body
});
 2).When Jquery founded and by whome?
 It was released in January 2006 at BarCamp NYC by John Resig(Jquery founder).
 
 
 3).What scripting language is jQuery written in?
 Ans: JavaScript
 
 
 4).Write a basic code for add jquery library to pages?
Code:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// You can write the code here
</script>
</head>
<body>
<a href="http://www.tutoriz.com/">Jquery Interview Questions and Answers</a>
</body>
</html>
 
 5).What is jQuery Selectors? Give some examples.
 Ans: Selectors are used in jQuery to find out DOM elements. Selectors can find the elements via ID, CSS, Element name and hierarchical position of the element.
Code:
Selector     Example          Selects
*           $("*")          All elements
#id          $("#lastname")      The element with id=lastname
.class          $(".intro")              All elements with
element      $("p")          All p elements
For more click here http://www.w3schools.com/jquery/jquery_r...ectors.asp
 
 
 6).What $("div.tutoriz") will select?
 Ans: All the div element with tutoriz class.
 
 
 7).jQuery uses CSS selectors and XPath expressions to select elements true or false?
 Ans:- True
 
 
 8).What are the fastest selectors in Jquery?
 Ans: ID and element selectors are the fastest selectors
 
 
 9).What are the slower selecoters in Jquery?
 Ans: Class selectors are slower
 
 10).Which one is faster Jquery ID selector or JavaScript getElementById()?
 (Jquery ID selector vs JavaScript getElementById())
 Ans: JavaScript getElementById() is faster than Jquery Id ($("#elementID")) selector
 
 
 11).Where Jquery code execute? On client browser or server browser?
 On client browser
 
 
 
 12).Write the code for selecting the
 1st div element, 4th div element
 last div, and for even and odd div elemets also.
 one by one?
 apply the red color on the above div.
Code:
<div>
<div> Question</div>
<div> Question</div>
<div> Question</div>
<div> Question</div>
<div> Question</div>
<div> Question</div>
</div>
Code for first div       : $("div.questions > div:first").css("color", "red");
Code for 4th div         : $("div.questions > div:nth-child(4)").css("color", "red");
Code for last div        : $("div.questions > div:last").css("color", "red");
Code for even div        : $("div.questions > div:even").css("color", "red");
Code for odd div         : $("div.questions > div:odd").css("color", "red");
 13).Write the code for select second last div element?
 Code for second last div : $("div.questions > div::nth-last-child(2)").css("color", "red"); <!-- Introduced in CSS3 -->
 
 14).What are the advantages of using jQuery over JavaScript in ASP.NET web application 
 Ans:
 Below are the advatages of using jQery over JavaScript
 a>.Jquery is well written optimised javascript code so
 it will be faster in execution unless we write same standard optimised javascript code.
 b>.Jquery is concise java script code ,means minimal ammount of code
 is to be written for the same functionality than the javascript.
 c>.Javascript related Development is fast using Jquery because most of the
 functionality is already written in the library and we just need to use that.
 d>.Jquery has cross browser support ,so we save time for supporting all the browsers. 
 
 
 15).What is Chaining in jQuery?
 Ans: 
 In jQuery, Chaining means to connect multiple functions, events on selectors. look at Sample Code 1 and 2.
Code:
Sample Code 1
​$(document).ready(function(){
$('#dvContent').addClass('dummy');
$('#dvContent').css('color', 'red');
$('#dvContent').fadeIn('slow');
});​

Sample Code 2 (using Chaining)
​$(document).ready(function(){
$('#dvContent').addClass('dummy')
.css('color', 'red')
.fadeIn('slow');
});​

Both the sample codes above will perform the exact same thing but the only difference is that Sample code 2 is using Chaining. But Code 2 is faster and shorter then Code 1.
 The problem with the Sample Code 1 is that for every statement, jQuery has to search the entire DOM and find the element and after that executes the attached function on it. But when chaining is used, then jQuery has to find the element only once and it will execute all the attached functions one by one. This is the advantage of Chaining.
 For read more click on the below link
 http://jquerybyexample.blogspot.com/2012...query.html
 http://tobiasahlin.com/blog/quick-guide-...in-jquery/
 
 16).Is jQuery a library for client scripting or server scripting?
 Ans: Client Script
 
 17).What is jQuery & its significance? Why it is so popular?...
 
 
 18).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 Handling
 
 
 19).How to check Jquery UI loaded or not?
 Ans: // Checking if jQuery UI is loaded or not
Code:
if($.ui){
// jQuery UI is loaded
}else {
// jQuery UI is not loaded
}
 20).How check currently loaded jQuery UI version on the page?
 Ans: // Returns jQuery UI version (ex: 1.8.2) or undefined
 $.ui.version
 
 
 21).Write the code for setting datetimepicker on textbox click.
 If below is our textbox 
 <input type="text" id="abc" name=%26quot%3Bacc%26quot%3B value="Select Date" />
 then Jquery code will be
 $("#abc").datepicker();
 
 
 
 22).If you have a table, how you will apply the two differt color on alternate rows using Jquery?
Code:
<table border="1">
<tr><td>Vikas Ahlawat</td></tr>
<tr><td>Edwin George</td></tr>
<tr><td>Rohit Khurana</td></tr>
<tr><td>Gyan Singh</td></tr>
</table>
Ans :
<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
$("tr:even").css("background-color", "#f4f4f8");
$("tr:odd").css("background-color", "#ffffff");
});
</script>
 
 23).Name the Jquery method which is used to hide selected elements?
 Ans: .hide()
 
 
 24).Name the Jquery methods which are used for apply css class?
 Ans:
 $("#Id1").addClass('YourClassName'); // for apply class
 $("#Id1").removeClass('YourClassName'); // for remove class
 
 
 25).What is the use of attr() method in Jquery?
 The attr() method sets or returns attributes and values of the selected elements.
 When this method is used to return the attribute value, it returns the value of the first matched element.
 When this method is used to set attribute values, it sets one or more attribute/value pairs for the set of matched elements.
Code:
$(selector).attr(attribute) //it will return the value of an attribute
$(selector).attr(attribute,value) //it will set the value of an attribute
$(selector).attr({attribute:value, attribute:value,...}) //for set multiple attribute
 26).Can we use both jQuery and AJAX together?
 Ans: yes
 
 27).Tell the name of jQuery method which is used to perform an asynchronous HTTP request?
 Ans: jQuery.ajax() 
 
 28).What is the use of jquery load() method?
 The jQuery load() method is a powerful AJAX method.
 The load() method loads data from a server and puts the returned data into the selected element without reload the complate page.
 Ex:The following example loads the content of the file "demo_test.txt" into a specific <div> element
 $("#div1").load("demo_test.txt");
 
 
 29).Can we use our own specific charactor in the place of $ sigh in Jquery?
 Ans: Yes
 You can also create your own shortcut very easily. The noConflict() method returns a reference to jQuery, that you can save in a variable, for later use. Here is an example:
Code:
var vikas = $.noConflict();
vikas(document).ready(function(){
vikas("button").click(function(){
vikas("p").text("jQuery is still working!");
});
});
 30).Name the 5 Jquery events?
 Ans:-
 jQuery Events
 jQuery click() event.
 jQuery dblclick() event.
 jQuery mouseenter() event.
 jQuery mouseleave() event.
 jQuery mousedown() event.
 jQuery mouseup() event.
 jQuery hover() event.
 jQuery focus() and blur() events.