jQuery

Q: What is the difference between onload() and document.ready()?
A: In a page, we can have only one onload function but we can have more than one document.ready function. Document.ready function is called when DOM is loaded but onload function is called when DOM and images are loaded on the page.

Q: What is the difference between find and children methods?
A: Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.

Q: What are the basic selectors in jQuery?
A: Following are the basic selectors in jQuery:
Element ID
CSS Name
Tag Name
DOM hierarchy

Q: What is the difference between size and length of jQuery?
A: Size and length both returns the number of element in an object. But length is faster than the size because length is a property and size is a method.

Q: Whether our own specific characters are used in place of $ in jQuery?
A: Yes, We can use our own variable in place of $ by suing the method called no Conflict () method.
var sample = $.noConflict()

Q: What are the parameters used for jQuery Ajax method?
A: The four parameters are
URL – Need to specify the URL to send the request
type – Specifies type of request(Get or Post)
data – Specifies data to be sent to server
Cache – Whether the browser should cache the requested page

Q: Explain .empty() vs .remove() vs .detach().
A:-.empty() method is used to remove all the child elements from matched elements.
-.remove() method is used to remove all the matched element. This method will remove all the jQuery data associated with the matched element.
-.detach() method is same as .remove() method except that the .detach() method doesn’t remove jQuery data associated with the matched elements.
-.remove() is faster than .empty() or .detach() method.

Q: What is CDN?
A: CDN Stands for Content Distribution Network or also called Content Delivery Network is a group of computers placed at various points connected with network containing copies of data files to maximize bandwidth in accessing the data. In CDN a client access a copy of data nearer to the client location rather than all clients accessing

Q: Why to load jQuery file from CDN?
A:You may ask that if we can load the jQuery file from our own server why to load it from the CDNs. The answer is logical and very simple. The browser behavior is that whenever it loads any webpage, it keeps related files (eg. Javascript file, CSS file and Images) used for that page into its cache (also called history). When next time the user browses any web page, browser loads only those files that are new or modified and is not available in the browser cache or history. In this way, browser improves its performance and loads the page.

The possibility is that if more and more websites are using CDNs, the user might have already browsed some other web pages that is using CDNs jQuery file and that file may have into browser cache; so when user browse your page and you are also using CDNs file, the older cached version of jQuery file will be used. In this way your page will load faster as browser will not have to load the jQuery file for your page again.

The benefit
1. Faster page load as jQuery file need not to be downloaded
2. Saves your bandwidth as jQuery file is not loaded from your server
3. Scalable – generally CDNs place these files on the servers located at different geographical locations of the world so that they load faster so irrespective of from where your user is browsing your page, your application runs well.

Leave a Reply

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