Jquery Interview Questions & Answers

  • Home
  • Interview_Question

Interview Questions & Answers



Select Series



How can you read properties of an Object in JavaScript?

You can write and read properties of an object using the dot notation as follows − // Getting object properties emp.name // ==> Zara emp.age // ==> 10 // Setting object properties emp.name = "Daisy" // <== Daisy emp.age = 20 // <== 20

How to read elements of an array in JavaScript?

An array has a length property that is useful for iteration. We can read elements of an array as follows − var x = [1, 2, 3, 4, 5]; for (var i = 0; i < x.length; i++) { // Do something with x[i] }

How can you get the type of arguments passed to a function?

Using typeof operator, we can get the type of arguments passed to a function. For example − function func(x){ console.log(typeof x, arguments.length); } func(); //==> "undefined", 0 func(1); //==> "number", 1 func("1", "2", "3"); //==> "string", 3

How can you get the reference of a caller function inside a function?

The arguments object has a callee property, which refers to the function you're inside of. For example − function func() { return arguments.callee; } func(); // ==> func

Give an example of closure?

Following example shows how the variable counter is visible within the create, increment, and print functions, but not outside of them − function create() { var counter = 0; return { increment: function() { counter++; }, print: function() { console.log(counter); } } } var c = create(); c.increment(); c.print(); // ==> 1

Which built-in method returns the character at the specified index?

charAt() method returns the character at the specified index.

Which built-in method calls a function for each element in the array?

forEach() method calls a function for each element in the array.

Which built-in method returns the length of the string?

length() method returns the length of the string.

Which built-in method returns the characters in a string beginning at the specified location?

substr() method returns the characters in a string beginning at the specified location through the specified number of characters.

Which built-in method returns the string representation of the number's value?

toString() method returns the string representation of the number's value.

How to select multiple elements using jQuery?

$('E, F, G') selects the combined results of all the specified selectors E, F or G where selectors can be any valid jQuery selector.

How can you apply a style on an element using jQuery?

The addClass( classes ) method can be used to apply defined style sheets onto all the matched elements. You can specify multiple classes separated by space.

How to add the previous selection to the current selection using jQuery?

The andSelf( ) method adds the previous selection to the current selection.

How to get a jQuery collection with the positioned parent of the first matched element?

The offsetParent( ) method returns a jQuery collection with the positioned parent of the first matched element.

How to get the top and left position of an element relative to its offset parent using jQuery?

The position( ) method gets the top and left position of an element relative to its offset parent.

How to set the width of an element using jQuery?

The width( val ) method sets the CSS width of every matched element.

How to remove set of matched elements using jQuery?

The remove( expr ) method removes all matched elements from the DOM.

How to stop the rest of the event handlers from being executed in jQuery?

The stopImmediatePropagation() method of Event object stops the rest of the handlers from being executed.

How to make a ajax call using jQuery?

The load( url, [data], [callback] ) method load HTML from a remote file and inject it into the DOM.

How to attach a function to be executed whenever an AJAX request completes using jQuery?

The ajaxComplete( callback ) method can be used to register a callback to be executed whenever an AJAX request completes.