What is JQuery?

JQuery is JavaScript 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 programmers to reduce lines of code as huge code written in JavaScript, can be done easily with JQuery in few lines.

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(){
});

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.

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="https://www.thegeekdiary.com/jquery-interview-questions-and-answers/_scripts/jQuery-1.3.2.js" type="text/javascript"></script>

and you are 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.

tell me name of 3 types of selectors in Jquery?

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

What is the basic use of jQuery() function?

  • Establish code to be executed when the DOM is ready for manipulation.
  • Help as a namespace for global utility functions.
  • Create DOM elements from HTML markup.
  • Select and wrap DOM elements to operate upon

which are basic selectors in jQuery (cross browser)?

  • Element ID’s
  • CSS class name
  • Tag name
  • last but not the least DOM hierarchy.

How do you select an item using css class or ID and get the value by use of jquery?

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 value:

var 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

How to get the server response from an AJAX request using Jquery?

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);
}
});

How do you update ajax response with id “resilts”?

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);
}
});
}

How do You disable or enable a form element?

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');

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

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');

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.

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 little 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.

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="https://www.thegeekdiary.com/jquery-interview-questions-and-answers/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.

What is JQuery UI?

JQuery UI is a library that is built on top of the JQuery library. JQuery UI comes with cool widgets, effects, and interaction mechanisms.

What are the 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

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 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 a newer version of the files are released, the older version remains there on the CDNs and your web page still works.

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="https://www.thegeekdiary.com/jquery-interview-questions-and-answers/jQuery-1.4.1-min.js"></script>