🔹 1. What is jQuery?
jQuery is fast, lightweight and feature-rich client side JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. It is one of the most popular client side library and as per a survey it runs on every second website.


🔹 2. What is the use of jquery .each() function?
The $.each() function is used to iterate over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is an object or an array.


🔹 3. Can we have multiple document.ready() function on the same page?
YES. We can have any number of document.ready() function on the same page.


🔹 4. What is a CDN?
A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.

There are 3 popular jQuery CDNs:

  1. 1. Google.
  2. 2. Microsoft
  3. 3. jQuery.

Advantages of using CDN:

  • It reduces the load from your server.
  • It saves bandwidth. jQuery framework will load faster from these CDN.
  • The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN

sp;


🔹 5. Is jQuery replacement of Java Script?
No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.


🔹 6. How do you select element by ID in jQuery?
To select element use ID selector. We need to prefix the id with “#” (hash symbol). For example, to select element with ID “txtName”, then syntax would be,

$(‘#txtName’)


🔹 7. What is jQuery.noConflict?
As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().

jQuery.noConflict();// Use jQuery via jQuery(…)jQuery(document).ready(function(){   jQuery(“div”).hide();});

You can also use your own specific character in the place of $ sign in jQuery.

var $j = jQuery.noConflict();// Use jQuery via jQuery(…)$j(document).ready(function(){   $j(“div”).hide();});


🔹 8. Is jQuery a library for client scripting or server scripting?
Client side scripting.


🔹 9. Is jQuery a W3C standard?
No. jQuery is not a W3C standard.


🔹 10. Why do we use jQuery?
Due to following advantages.

  • Easy to use and learn.
  • Easily expandable.
  • Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
  • Easy to use for DOM manipulation and traversal.
  • Large pool of built in methods.
  • AJAX Capabilities.
  • Methods for changing or applying CSS, creating animations.
  • Event detection and handling.
  • Tons of plug-ins for all kind of needs.

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


🔹 12. What is event.PreventDefault?
The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.


🔹 13. How JavaScript and jQuery are different?
JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.


🔹 14. What is the difference between .js and .min.js?
jQuery library comes in 2 different versions Development and Production/Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library file. Both the files are same as far as functionality is concerned. but .min.js is quite small in size so it loads quickly and saves bandwidth.


🔹 15. Which is the starting point of code execution in jQuery?

The starting point of jQuery code execution is $(document).ready() function which is executed when DOM is loaded.


🔹 16. What does $(“div”) will select?
This will select all the div elements on page.


🔹 17. How to select element having a particular class (“.selected”)?

$(‘.selected’). This selector is known as class selector. We need to prefix the class name with “.” (dot).


🔹 18. What does $(“div.parent”) will select?
All the div element with parent class.


🔹 19. Is there any difference between body onload() and document.ready() function?
document.ready() function is different from body onload() function for several reasons:

  1. We can have more than one document.ready() function in a page where we can have only one body 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.

🔹 20. How to create clone of any object using jQuery?

jQuery provides clone() method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.

$(document).ready(function(){  $(‘#btnClone’).click(function(){     $(‘#dvText’).clone().appendTo(‘body’);     return false;  });});

The default implementation of the clone() method doesn’t copy events unless you tell the clone() method to copy the events. The clone() method takes a parameter, if you pass true then it will copy the events as well.

$(document).ready(function(){   $(“#btnClone”).bind(‘click’, function(){     $(‘#dvClickme’).clone(true).appendTo(‘body’);  });


🔹 21. What is chaining in jQuery?
Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.

Consider:

$(document).ready(function(){    $(‘#dvContent’).addClass(‘dummy’)          .css(‘color’, ‘red’)          .fadeIn(‘slow’);     });​


🔹 22. Which is fast document.getElementByID(‘txtName’) or $(‘#txtName’).?
Native JavaScipt is always fast. jQuery method to select txtName “$(‘#txtName’)” will internally makes a call to document.getElementByID(‘txtName’). As jQuery is written on top of JavaScript and it internally uses JavaScript only so JavaScript is always fast.


🔹 23. What is the difference between event.PreventDefault and event.stopPropagation?

  • event.preventDefault(): Stops the default action of an element from happening.
  • event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.

🔹 24. What is the difference between parent() and parents() methods in jQuery?

The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.


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

jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.


🔹 26. What is difference between prop and attr?
attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas, .prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in the set of matched elements.

Attributes carry additional information about an HTML element and come in name=”value” pairs. Where Property is a representation of an attribute in the HTML DOM tree. once the browser parse your HTML code ,corresponding DOM node will be created which is an object thus having properties.

attr() gives you the value of element as it was defines in the html on page load. It is always recommended to use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element’s current state.


🔹 27. What is the difference between eq() and get() methods in jQuery?

  • eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.
  • get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can’t be used.

🔹 28. What are various methods to make ajax request in jQuery?
Using below jQuery methods, you can make ajax calls.

  • load() : Load a piece of html into a container DOM
  • $.getJSON(): Load JSON with GET method.
  • $.getScript(): Load a JavaScript file.
  • $.get(): Use to make a GET call and play extensively with the response.
  • $.post(): Use to make a POST call and don’t want to load the response to some container DOM.
  • $.ajax(): Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.

🔹 29. When would you use AngularJS vs jQuery?

  • jQuery – is a library used for DOM Manipulations – Has nothing to do with models – don’t have two-way binding feature – becomes complex and difficult to maintain when size of project increases – Sometimes you have to write more code to achieve the same functionality as in Angular
  • Angular – is a MVVM Framework – Used for creating SPA (Single Page Applications) – Has key features like routing, directives, two way data binding, models, dependency injection, unit tests etc – is modular – Maintainable, when project size increases – is Fast and many more.

Basically jQuery is a single tool (solves one specific problem: dom manipulation) where AngularJS is a whole toolbox with all kind of tools for different problems (routing, modelbindings, dom manipulation, etc.). Actually jqLite (subset of jQuery) is part of the AngularJS and you use it to solve the dom-manipulation thing.


🔹 30. What are selectors in jQuery and how many types of selectors are there?

To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:

  • Name: Selects all elements which match with the given element Name.
  • #ID: Selects a single element which matches with the given ID
  • .Class: Selects all elements which match with the given Class.
  • Universal (*): Selects all elements available in a DOM.
  • Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
  • Attribute Selector: Select elements based on its attribute value.
Back to list

Leave a Reply

Your email address will not be published. Required fields are marked *