jQuery Interview Questions
This page consists of jQuery interview questions and answers.
jQuery is a fast, feature rich, client side JavaScript library with the moto "Write less, do more".
No.
jQuery is written in JavaScript and is a JavaScript code.
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');
$()
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");
el.hide();
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...
});
$(document).ready()
function in a page?Yes we can use multiple $(document).ready()
function in a 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>
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.
Following are the selectors used in jQuery.
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.
ADVERTISEMENT