jQuery Interview Questions (Part-2)
Is jQuery a W3C standard?
Is jQuery is a client or server scripting?
Can JQuery Run on MAC or Linux instead of Windows?
JQuery support cross browser and cross platform compatibility hence it simply runs on Windows, MAC, or Linux with all major browser compatibility.
Where jQuery code is getting executed?
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).
Which is the starting point of code execution in jQuery?
What are all the ways to include jQuery in a page?
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
What are the two types of CDNs?
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:
Can we use protocol less URL while referencing jQuery from CDNs?
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.
How to resolve conflicts with other libraries?
How to execute jQuery code after the DOM is ready?
Or use the shortcut
Which sign is used as a shortcut for jQuery?
By default, jQuery uses "$" as a shortcut for "jQuery".
Can you use any other name in place of $ (dollar sign) in 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.
Can we add more than one "document.ready" function in a page?
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.
What is the difference between "#" and "." selector in JQuery?
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.
How We Can Write Code Specific To Browser In Jquery?
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.
What is the difference between jQuery and jQuery UI?
How to debug 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
Which program is useful for testing jQuery?
Whether jQuery HTML work for both HTML and XML documents?
No, jQuery HTML only works for HTML documents not for XML Documents.
Differentiate the concepts of .js and .min.js?
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.
How to resolve confict with another JS library if $ is already being in use?
Try a new alias to jQuery.
What are the frequently used type of selectors in 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").
Difference between width() and css('width')?
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.
What is the difference between jquery.size() and jquery.length?
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.
What is difference between $(this) and this in jQuery ?
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'.
What is the difference between find and children methods?
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.
How to get the direct parent of an element using jQuery?
$(element).parent() returns the immediate parent.