jQuery

  Home  World Wide Web  jQuery


“jQuery Interview Questions and Answers guide is a simple way to learn jQuery. Here you will learn that jQuery is a fast, brief and smallest JavaScript Library that simplifies our HTML document traversing, its event handling, its animation, and Ajax interactions with application for rapid web development. jQuery is designed for the enhancement of JavaScript and AJAX. This jQuery Tutorial and Interview Questions and Answers will guide all of us that jQuery is a lightweight JavaScript library.”



91 JQuery Questions And Answers

81⟩ Derfine width() vs css('width')?

In jQuery, there are two way to change the width of an element.

One way is using .css('width') and other way is using .width().

For example:

$('#mydiv').css('width','300px');

$('#mydiv').width(100);

★ The difference in .css('width') and .width() is the data type of value we specify or return from the both functions.

★ In .css('width') we have to add "px" in the width value while in .width() we don't have to add.

★ When you want to get the width of "mydiv" element then .css('width') will return '300px' while .width() will return only integer value 300.

 175 views

82⟩ Define each() function in jQuery?

The each() function specify the function to be called for every matched element.

Syntax:

$(selector).each(function (index, element))

"index" is the index position of the selector.

"selector" specifies the current selector where we can use "this" selector also.

In the case when we need to stop the each loop early then we can use "return false;"

For example:

$("#clickme").click(function(){

$("li").each(function(){

document.write($(this).text())

});

});

This will write the text for each "li" element.

 206 views

83⟩ Define slideToggle() effect?

slideToggle() effect is used to give animated sliding effect to an element.

Syntax:

slideToggle([ duration] [, easing] [, callback])

"duration" is the number specifying how long the animation will run.

"easing" is the string which specify the function for the transition.

"callback" is the function which we want to run once the animation is complete.

If the element is visible then this effect will slide the element up side and make it completely hidden. If the element is hidden then slideToggle() effect will slide it down side and make it visible.

We can specify the toggle speed with this effect.

For example:

$("#clickme").click(function(){

$("#mydiv").slideToggle("slow", function(){

//run after the animation is complete.

});

});

 190 views

84⟩ Explain the difference between $(this) and 'this' in jQuery?

Refer the following example:

$(document).ready(function(){

$('#clickme').click(function(){

alert($(this).text());

alert(this.innerText);

});

});

★ this and $(this) references the same element but the difference is that "this" is used in traditional way but when "this" is used with $() then it becomes a jQuery object on which we can use the functions of jQuery.

★ In the example given, when only "this" keyword is used then we can use the jQuery text() function to get the text of the element, because it is not jQuery object. Once the "this" keyword is wrapped in $() then we can use the jQuery function text() to get the text of the element.

 188 views

85⟩ How to read, write and delete cookies in jQuery?

★ To deal with cookies in jQuery we have to use the Dough cookie plugin.

★ Dough is easy to use and having powerful features.

Create cookie:

$.dough("cookie_name", "cookie_value");

Read Cookie:

$.dough("cookie_name");

Delete cookie:

$.dough("cookie_name", "remove");

 234 views

87⟩ jQuery can be used in what scenarios?

jQuery can be used in following scenarios:

★ Apply CSS static or dynamic

★ Calling functions on events

★ Manipulation purpose

★ Mainly for Animation effects

 185 views

90⟩ Define all the ways to include jQuery in a page?

Following are the ways to include jQuery in a page:

★ Local copy inside script tag

★ Local copy of script manager control

★ Embedded script using client script object

★ Remote copy of jQuery.com

★ Remote copy of Ajax API

 218 views

91⟩ What are jQuery Selectors?

★ 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.

 185 views