jQuery Interview Questions - Set 1

jQuery Interview Questions

Next →

This page consists of jQuery interview questions and answers.

Q1: What is jQuery?

jQuery is a fast, feature rich, client side JavaScript library with the moto "Write less, do more".

Q2: Is jQuery a new programming language?


jQuery is written in JavaScript and is a JavaScript code.

Q3: What is the difference between JavaScript and jQuery?

Under the hood jQuery is JavaScript but jQuery makes writing JavaScript code much easier.

For example if we want to select a div having id "container" then in plain JavaScript we will write the following code.

var el = document.getElementById('container');

In jQuery we have to write the following to achieve the same result.

var el = $('#container');

Q4: What is $() in jQuery?

The $() is an alias of the jQuery() function.

If we pass a selector then it will return jQuery object with some methods which can be used to perform different tasks.

In the following example we are selecting a div having id 'container' and hiding it from the page.

var el = $("#container");

Q5: How to execute jQuery code after the DOM is ready?

For this we write the following code.

$(document).ready(function() {
  // some code goes here...

Since the above code is used quite frequently so there is a shortcut for that.

$(function() {
  // some code goes here...

Q6: Can we use multiple $(document).ready() function in a page?

Yes we can use multiple $(document).ready() function in a page.

Q7: How will you include jQuery file in your HTML page?

We use the script tag and set the src attribute to the jQuery file.

In the following code we are including jQuery file from a CDN.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Q8: What is the advantage of using CDN for jQuery file?

CDN (Content Delivery Network or Content Distribution Network) provides content to the end user with high performance and availability.

Following are the advantages of using CDN.

  • Reduces load on the server.
  • Saves bandwidth.
  • Helps loading jQuery file in the web page faster.
  • jQuery from CDN also gets cached.

Q9: What are the different selectors in jQuery?

Following are the selectors used in jQuery.

  • CSS Selector
  • Custom Selector
  • XPath Selector

Q10: Write jQuery code to select all the paragraphs in the page

For this we will write the following code.

var elems = $("p");

The elems variable will hold zero or more paragraphs depending on the number of paragraphs present in the web page.

Next →