banner
Sep 24, 2014
59 Views
0 0

JQuery Interview Questions

Written by
banner

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

e.g.

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

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 .
Ans:

$('#divid').submit(function() {
$(this).find("input[type='submit']").attr('disabled',true);
});
or
$('.divclass').submit(function() {
$(this).find("input[type='submit']").attr('disabled',true);
});

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');
or
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':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});

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

Another way is :
$(".formclass").get().reset();

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 ,
e.g.

$.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”
src=”http://code.jquery.com/jquery-latest.min.js”>
</script>

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

Share this:
Article Categories:
Interview Question · jQuery · Odesk · Web Development
banner

Hi, to my all friends , this blog for you to just share my knowledge on different sections .

Leave a Comment

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

Result of *

Social Widgets powered by AB-WebLog.com.