JQuery Interview Questions

1. How to get value and text of a selected element from Dropdown by jQuery ?
value=$(‘#selectid option:selected’).val();
text=$(‘#selectid option:selected’).text();


<select id="myselect">
<option value="1">Label 1</option>
<option value="2" selected="selected">Label 2</option>
<option value="3">Label 3</option>

value=$(‘#myselect option:selected’).val(); //2
text=$(‘#myselect option:selected’).text(); //Label 2

2. Disable Submit button on form submit under a div by jQuery .

$('#divid').submit(function() {
$('.divclass').submit(function() {

3. How to off Auto complete of text box under a

tag ?
Ans: By the property of autocomplete making off you can do this . Here is the example code:

By div id:
$("#divid input[type='text']").attr('autocomplete', 'off');
By div class name:
$(".divclass input[type='text']").attr('autocomplete', 'off');

4. How to make all input fields reset by jQuery?
Ans: Both way it can be possible by making fields blank and making reset of check box or radio box , the other way is by using reset() function of jQuery . Here are the example of both way:

$("#formid").find(':input').each(function() {
switch(this.type) {
case 'password':
case 'text':
case 'textarea':
case 'file':
case 'select-one':
case 'select-multiple':
case 'checkbox':
case 'radio':
this.checked = false;

You can use ".formclass" instead of "#formid" .

Another way is :

5. Explain the each() function
Ans: The each() function specify the function to be called for every matched element. It traverse each matched element and retrieve as an object .
You can take example from #4 question from the above list.

6. What is jQuery.holdReady() function?
Ans : This is very interesting function in jquery when we need to get delay the ready function we must call this

function before $(document).ready(function fn(){
//code goes here

7. How to get value of a Cookie in jQuery ?
Ans: Now , Klaus Hartl makes a easy way to get the value of Cookie by using jQuery Cookie Plugin . Here is the link for jQuery Cookie Plugin
To get the value of cookie ,

$.cookie('cookiename'); // => "value"

8. How to always get latest version of jQuery?
Ans: In this case jQuery made us easy :
To achieve this you have to use following code

<script type=”text/javascript”

9. How JavaScript and jQuery are different?
Ans: Everybody asking this question in interview , so the answer is , Javascript is a language and jQuery is the library based on Javascript .

10. What are the basic selectors in jQuery?

Ans: Here are the basic selectors in jQuery:
i.Element ID
ii.CSS Name
iii.Tag Name
iv.DOM Object

Leave a Reply

Your email address will not be published. Required fields are marked *

Result of *Captcha loading...