Monday, 16 December 2013

JQuery - 1

http://www.jquerybyexample.net/
http://gregfranko.com/jquery-best-practices/#/22



1.What is jQuery?

Ans: 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.Why do we use jQuery?

Ans: 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.
 
3.What is the difference between .js and .min.js?
 
Ans: jQuery library comes in 2 different versions Production and 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.

4. What is JQuery UI?

Ans: jQuery UI is a library which is built on top of jQuery library. jQuery UI comes with cool widgets, effects and interaction mechanism.

 5. What does dollar Sign ($) means in JQuery?

Ans: 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(){ });

6.What is jQuery Selectors? Give some examples.
  •  jQuery Selectors are used to select one or a group of HTML elements from your web page.
  •  jQuery support all the CSS selectors as well as many additional custom selectors.
  •  jQuery selectors always start with dollar sign and parentheses: $()
  •  There are three building blocks to select the elements in a web document.
1) Select elements by tag name
    Example: $(div)
    It will select all the div elements in the document.
2) Select elements by ID
    Example: $(#xyzid”)
    It will select single element that has an ID of xyzid
3) Select elements by class
    Example: $(“.xyzclass”)
    It will select all the elements having class xyzclass

 
7.Is there any difference between body onload() and document.ready() function?
 
Ans: document.ready() function is different from body onload() function for 2 reasons.
  • We can have more than one document.ready() function in a page where we can have only one body onload function.
  • 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.
8.What is difference between prop and attr?
  • In jQuery both prop() and attr() function is used to set/get the value of specified property of an element.
  • The difference in both the function is that attr() returns the default value of the property while the prop() returns the current value of the property.
For example
<input value="My Value" type="text"/>
 $('input').prop('value', 'Changed Value');
 -.attr('value') will return 'My Value'
 -.prop('value') will return 'Changed Value'
 
9.Can we have multiple document.ready() function on the same page?
 
Ans: YES. We can have any number of document.ready() function on the same page.

10.What is jQuery.noConflict?
 
Ans: 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();
}); 

11.Name some of the methods of JQuery used to provide effects?

Ans: Some of the common methods are :
  •    Show()
  •    Hide()
  •   Toggle()
  •   FadeIn()
  •   FadeOut()

No comments:

Post a Comment