JQuery Interview Questions and Answers Part 2

1. How to find mouse click coordinates using jquery?

  alert("(" + event.pageX + "," + event.pageY + ")");

2. Difference between Event Capturing and Event Bubbling in jquery?

Event Capturing : The event handler of element1 fires first, the event handler of element2 fires last.

Event Bubbling : The event handler of element2 fires first, the event handler of element1 fires last.

3. How to define own specific shortcut character for Jquery?
Ans. Yes, we can define our own shortcut character instead of '$' using jquery.
var $my = jQuery.noConflict();
Now use this shortcut like the following code,

4. How to disable or enable a form element using jquery?
Ans. An element can be disabled or enabled using setting the 'disabled' attribute to true or false.
Example :
// Disabling 
$('#elementid').attr('disabled', true);
// Enabling
$('#elementid').attr('disabled', false);

5. Get the dropdown value using jquery?
<select id="city">
   <option value="1">newyork</option>
   <option value="2">washington</option>
   <option value="3">london</option>
   <option value="4">capetown</option>  

Ans. suppose if we select washington in the dropdown box we can get that text and value of it
by using the following code,

$("#city option:selected").text(); => washington
$("#city").val(); => 1

6. How to select all the elements on the DOM using Jquery?
Ans. $("elementname") will select all the elements on the page.

7. Which is the fastest selector in jQuery class or id or element?
Ans: ID, Element and Class selectors are the fastest priority wise in jQuery.

8. If we want the element with a class, how do we get using jquery?
Ans. $("elementname.classname") will do the needful.

9. How to hold the document.ready execution for sometime using jquery?
Ans. Their is a possibility to hold or delay the document.ready function execution using jquery.
Example : 
$.getScript("scriptname.js", function() {

10. Can we call server side code from jquery?
Ans. By using '$.ajax' we can call the server side code.


Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker