jQuery Interview Questions FAQ
Please click on the questions to see the answers
JQuery support cross browser and cross platform compatibility hence it simply runs on Windows, MAC, or Linux with all major browser compatibility.
jQuery code runs on the web browser.
In general, jQuery code is executed on the client side. But jQuery also give you the ability to call a particular function or action onto your server by sending 'xml-http Ajax request(jqXHR)' targeted specific server-side url, and receiving the response content in many different formats such as (html, Json, xml and so on).
There are several ways to start using jQuery on your web site. You can:
- Download a local copy from jQuery.com
- Link to a file via Content Delivery Network (CDN), like Google
Both Microsoft and Google already host jQuery on their CDNs. When to use jQuery from Google or Microsoft, use one of the following:
If you wish to use jQuery CDN other than Google or Microsoft hosted jQuery library, you might consider using this and ensures uses the latest version of jQuery:
Yes. The "protocol-less" URL is the best way to reference third party content that's available via both HTTP and HTTPS. When a URL's protocol is omitted, the browser uses the underlying document’s protocol instead.
Or use the shortcut
By default, jQuery uses "$" as a shortcut for "jQuery".
You can use $ or jQuery signs. By default, jQuery uses "$" as a shortcut for "jQuery".
So, using $("#id") or jQuery("#id") is the same.
jQuery has many ways of accessing its library:
jQuery or window.jQuery can be used instead of $ if you were using more than one library.
Yes. You can use multiple document ready handler, there is no special advantage even though you can use jQuery code in several place. All will get executed on first called first run basis. It is important to note that each jQuery() call must actually return. If an exception is thrown in one, subsequent calls will never be executed.
The "#" is used to select by id:
It will select one and only one element which have id myID.
The '.' is used to select elements by class:
It will select all the elements which have class as myClass.
jQuery provides jQuery.browser property which returns the browser information. The $.browser property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery.
- Hit the F12 key
- Select the Scripts, or Sources, tab in the developer tools
- Click the little folder icon in the top level
- Add a breakpoint by clicking on the line number on the left
No, jQuery HTML only works for HTML documents not for XML Documents.
jQuery.min.js is a compressed version of jQuery.js. In terms of functionality, there is no difference between the jQuery.js and jQuery.min.js. The difference is only in whether it's formatted nicely for readability or compactly for smaller file size(jQuery.min.js).
You are able to read jQuery.js and understandable. The unnecessary characters are removed in jQuery.js.min for fast loading purposes and less size. The removal of whitespace removes line breaks and spaces messing up the formatting, and the shortening of variable names (including some function names) replaces the original variable names with meaningless letters. It is better using the minified version (.min) for your live environment as Search Engines are now checking on page loading times.
jQuery.noConflict() method allows you to use multiple frameworks, while using jQuery.
It is important to note that, even with noConflict it is possible for problems to occur. Libraries use different internal methods to manipulate events and DOM nodes. There is the possibility of subtle bugs that noConflict is unable to prevent.
Try a new alias to jQuery.
Selectors allow page elements to be selected. The frequently used type of selectors in jQuery are:
- ID Selector - Selects the element with the ID using the '#' keyword.
- Class Selector - Selects the element with the class name using the '.' keyword.
- Element Selector - Selects the element using its type Ex. $("p").
jQuery allows two ways to set width and height of any element. You can set using css or you can use jQuery provided methods. The difference between jQuery width() and css(width) is that the jQuery width() returns a unit-less pixel value (for ex. 100) while the css(width) returns a value with units intact (for ex. 100px). The jQuery width() method is recommended when an element's width needs to be used in a mathematical calculation.
jQuery.size() and jQuery.length both returns the number of element in an object. But the jQuery.length property is preferred because it does not have the overhead of a function call. Moreover, jQuery.size() deprecated in jQuery 1.8 and completely removed in jQuery 3.0.
The this is the DOM object and $(this) is jquery object wrapper around 'this' DOM object.
When using 'this' you can directly access the DOM node that's being processed, but not jQuery object. When using $(this), you can call jQuery methods on it, but not DOM object. In many cases it's better to use plain 'this'.
The jQuery $.find method may travel through multiple levels down to get the descendent elements. Whereas, the $.children method can go to just one level down.
$(element).parent() returns the immediate parent.
- jQuery Interview Questions FAQ - 2
- Is jQuery a programming language?
- Why do we need to go for JQuery?
- How to check jQuery version?
- How to multiple version of jQuery?
- What is jQuery CDN?
- Advantages of minified version of JQuery
- How do I check if the DOM is ready?
- How to Use the jQuery load() Method
- Difference between document.ready() and body onload()?
- What is the use of param() method?
- How to work with jQuery parent(), children() and siblings()?
- Difference between parent() and parents() in jQuery?
- What does jQuery data() function do?