jQuery Interview Questions (Part-2)
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).
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:
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.
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:
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.
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
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.
- jQuery Interview Questions (Part-3)
- 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?
- How do you check if an element exists or not in jQuery?
- How do I check if an HTML element is empty using jQuery?
- How to run an event handler only once in jQuery?
- How to disable/enable an element with jQuery
- Hide and show image on button click using jQuery
- Difference Between Prop and Attr in jQuery
- How do I check if an element is hidden in jQuery?
- What happen if you return false from a jQuery event handler?
- What is each() function in jQuery? How do you use it?
- Which one is more efficient, document.getElementbyId( "myId") or $("#myId)?
- What is the difference between $.map and $.grep in jQuery
- What is the use of serialize method in jQuery
- What is the use of clone method in jQuery?
- What is event.PreventDefault in jQuery?
- Difference between event.PreventDefault and event.stopPropagation?
- What are deferred and promise object in jQuery?
- What are source maps in jQuery?
- What does the jQuery migrate function do?
- Differences Between jQuery .bind() and .live()?
- How can you delay document.ready until a variable is set?
- How to disable cut,copy and paste in TextBox using jQuery?
- How to prevent Right Click option using jquery?
- How does the jQuery pushStack function work?
- Why use jQuery filter() Methods?
- Difference between find() and closest() in jquery?
- How To Use Ajax In Jquery?
- How to multiple AJAX requests be run simultaneously in jQuery?
- Can we call C# code behind using jQuery?
- How to include jQuery in ASP.Net project?
- Need to add jQuery file in both Master and Content page?
- Uncaught TypeError: $(…).modal is not a function jquery
- How to check whether a checkbox is checked in jQuery?
- Uncaught ReferenceError: $ is not defined