Q) What is jQuery?

A) jQuery is a fast and concise JavaScript library(created with motto write less and do more).
jQuery simplifies html document traversing, event handling, animating and ajax interactions for rapid development.


Q) What are features of jQuery?

A) The main features of jQuery are as follows:
DOM manipulation: jQuery make it easy to select DOM elements, modify their content.
Event handling: Events handling like button click, etc.
Animations: jQuery comes with built in animations
Light weight, Fast and extensible
Cross browser support
Facilitates to write minimum code.


Q) What is $() factory function in jQuery?

A) All type of selectors available in jQuery, always start with dollar sign and parenthesis:$().
The factory function makes use of following three building blocks while selecting in given document.
1.Tag Name: Example: $(‘P’) selects all paragraphs in document.

2.Tag Id: Example:$(‘#Button1’) selects element in document with Id button1

3.Tag class: Example:$(‘.Class1’) selects all elements in document that have class name as class1

Note:$() is a synonym of jQuery() function. We can use jQuery instead of using $().


Q) What is starting point of jQuery?

A) $(document).ready() is the starting point of jQuery
Example:

$(document).ready(function()
{
  //Your code
})

Q) Syntax of basic function in jQuery.

A) The below example writes “Hi” with the help of jQuery library.

<head>
<script type="textbox/javascript"  src="/jQuery/..js"></script>
<script type="text/javascript">
$(document).ready()(function(){
document.write("Hi");
});
</script>

Q) How to use selectors?

A) Selectors are required when we need to get exact element that we want from Html document.
Below are the examples of selectors:

Name:Selects all elements which match with given element name

Id: Selects single element which match with given ID

.Class: Selects all elements which matches with given class.
Universal(): Selects all elements available in a DOM(Example : $(‘‘))


Q) Explain few Attribute methods in jQuery.

A) The below are few examples of Attribute methods:

attr(properties): It is used to set a key/value object as properties to all matched elements
Example:

$('img').attr({
src:"/images/A.jpg",
title:"jquery",
alt:"logo"
});

attr(key,func): this method sets a single property to a computed value.
Example:

$("table").attr("border",function(arr)
{
return arr;
})

removeAttr: It is used to remove attribute from given element
Example:

$("table").removeAttr("border");

hasClass(): It is used to check if element has the given class

removeClass(): It is used to remove class from given element

html(): It is used to get html contents of first matched element.

html(val): It is used to set html contents of every matched element.

text(): Gets combined text contents of all matched elements.

text(val): Used to set text to given element.

val(): It gets the input value of first matched element.

val(val): sets the input value of every matched element.


Q) Explain a few methods in jQuery.

A) blur(): Triggers the blur event of each matched element.

blur(function): Binds a function to blur event.

change: Triggers change event of exact matched element

click:It is used to handle click events

click(function): It is used to bind a function on click event.

dblclick: It is used to handle double click events.

dblclick(function): It is used to bind a function on double click.

The other methods in jQuery include: error, error(function), focus, focus(function), keydown, keypress, keyup, load etc.


Q) Name some effects in jQuery.

A) The below are some effects in jQuery:
show()
hide()
toggle()
fadeIn()
fadeOut()


Q) What is the difference between size and length in jQuery?

A)Both size and length return number of elements in an object. But length is faster than size because length is a property and size is a method.


Q) What is the difference between body.onLoad() and document.ready()?

A)The below are two major differences between body.onLoad() and document.ready() methods:

1.We can have more than one document ready where as we can have only one body.onLoad.

2.document.ready gets as soon as DOM is loaded where as body.onLoad() gets called when everything is loaded which includes DOM, images and all associated resources of page.