JQuery Programmer

  Home  Client Side Scripting  JQuery Programmer


“JQuery Programmer Frequently Asked Questions in various JQuery Developer job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”



154 JQuery Programmer Questions And Answers

101⟩ What is 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.

 213 views

102⟩ What is the difference between event.PreventDefault and event.stopPropagation?

event.preventDefault(): Stops the default action of an element from happening.

event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.

 227 views

110⟩ What is finish method in jQuery?

The .finish() method stops all queued animations and places the element(s) in their final state. This method was introduced in jQuery 1.9.

 238 views

114⟩ Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?

By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.

Where jQuery.ajax() is jQuery's low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don't offer as much functionality (such as error callbacks).

 219 views

120⟩ How can events be prevented to work after an ajax request?

here are two ways to handle this issue:

1. Use of event delegation : The event delegation technique works on principle by exploiting the event bubbling. It uses event bubbling to capture the events on elements which are present anywhere in the domain object model. In jquery the user can make use of the live and die methods for the events delegation which contains a subset of event types.

For ex. Handling even delegation, handling of clicks on any <a> element:

$('#mydiv').click(function(e)

{

if( $(e.target).is('a') )

fn.call(e.target,e);

});

$('#mydiv').load('my.html')

2. Event rebinding usage : When this method is used it requires the user to call the bind method and the added new elements.

For ex.

$('a').click(fn);

$('#mydiv').load('my.html',function()

{

$('#mydiv a').click(fn);

});

 204 views