Interview Questions on JQuery

41. Explain fadein and fadeout?

Syntax : - $("element").fadin();
Ex :- 
$( "#clickme" ).click(function() {
  $( "#book" ).fadeIn( "slow", function() {
    // Animation complete
  });
});

42. Explain animate?

Syntax :- $("#idname").animate({//apply styles});
Ex :- $("#box").animate({height: "300px"});

43. How to execute function periodically?

setInterval(function () {   
      //call functions here     
}, 3000);

Questions 41 - Last

Interview Questions on JQuery

31. How to write “ in string that is enclosed with in double quotes?

Use \”

32. How to remove extra white space?

The $.trim() function removes all newlines 
Ex :- 
var str = "         lots of spaces before and after         ";
$( "#original" ).html( "Original String: '" + str + "'" );
$( "#trimmed" ).html( "$.trim()'ed: '" + $.trim(str) + "'" );

33. How to create an array in javascript?

Method1 :- var cars = ["Saab", "Volvo", "BMW"];
Method2 :-  var cars = new Array("Saab", "Volvo", "BMW");

34. How to find the size of an array?

Syntax :- arrayname.legth;
Ex:- 
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var legth = fruits.length;
length contains 4

35. How to sort the elements in alphabetical order in ascending?

Syntax : - arrayname.sort();
Ex:- 
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
// fruits contains : Apple,Banana,Mango,Orange

36. How to sort the elements in alphabetical order in descending?

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
fruits.reverse();
// fruits contains : Orange,Mango,Banana,Apple

37. How to disable right click in jQuery?

$(document).ready(function(){
    $(document).on("contextmenu",function(e){
        if(e.target.nodeName != "INPUT" && e.target.nodeName != "TEXTAREA")
             e.preventDefault();
     });
 });

38. How to submit a form without mouse click on submit button?

Use :    document.forms["formname"].submit();

39. How to redirect to another page?

Use :-  window.location="url_name";

40. How to hide particular div?

Syntax : - $("element").hide();
Ex :- $(".target").hide();

Questions 31 - 40

Interview Questions on JQuery

21. How to take action when particular button clicked?

$(‘element’).click(handler);
Ex:- 
$( "#target" ).click(function() {
  alert( "Handler for .click() called." );
});

22. How take action when form is submitted?

$(‘element’).submit(handler);
Ex:- 
$( "#form1" ).submit(function() {
  alert( "Handler for .click() called." );
});

23. How to take action when particular input box got focus in?

Syntax :- 
$(‘element’).focusin(handler);
Ex :-
$( "p" ).focusin(function() {
  $( this ).find( "span" ).css( "display", "inline");
});

24. How to take action when particular input box got focused out?

$(‘element’).focusout(handler);
Ex :-
$( "p" ).focusout(function() {
  $( this ).find( "span" ).css( "display", "inline");
});

25. How to take action when key pressed in input box?

$(‘element’).keypress(handler);
Ex :-
$( "p" ).keypress(function() {
  $( this ).find( "span" ).css( "display", "inline");
});

26. How to take action when mouse over on hyperlik?

$(‘element’).mouseover(handler);
Ex :-
$( "a" ).mouseover(function() {
  $( this ).css( "color", "#333");
});

27. How to take action when mouse leaves on hyperlik?

$(‘#elementid’).mouseleave(handler);
Ex :-
$( "#outer" ).mouseleave(function() {
  $( "#log" ).append( "<div>Handler for .mouseleave() called.</div>" );
});

28. How to take action select option from dropdown list?

$( "element" ).change(handler);
Ex :-
$( ".target" ).change(function() {
  alert( "Handler for .change() called." );
});

29. How to execute jQuery statement after browser loading entire html page?

use $( document ).ready(handler);
$( document ).ready(function() {
    console.log( "ready!" );
});

30. What are the uses of jQuery over javascript?

a. its light weight when compared to other javascript frameworks.
b. it has a wide range of plugins available for various specific needs.
c. it is easier for a designer to learn javascript as it uses familiar CSS syntax. jQuery is Javascript for Designers.

Questions 21 - 30

Interview Questions on JQuery

11. How to get value of input box?

$('#id’).val();
Ex :- var bla = $('#tinput_id1’).val();

12. How to declare and initialize variables?

Var varname = value
Ex:- var var1=5;

13. How to concat two strings in jQuery?

Use +
Ex 1:- var string = “string1”+”string2”;
Ex :- var str1=”string1”;
Var str2 =”string2”;
Var string3=  str1+str2;

14. How to write comments in jQuery?

Method 1 : //commentd goes here
Method 2 :- /* comments goes here */

15. How to convert string to number?

Use parseInt(stringvalue);
Ex:- var var1= parseInt(‘3’);

16. How to convert number to string?

Use toString() method.

17. How to create an array in jQuery?

Just like in javasctipt.
Var arrayname=[value1,value2,calue3];
Ex :- var array1=[3,6,8];

18. What is function?

Def :- Set of statements to perform a particular operation.
Syntax :- 
function function_name(arg1,arg2){
//body
}
Ex :- 
function myFunction(p1, p2) {
    return p1 * p2;   
    // The function returns the product of p1 and p2
}

19. Can we access local variable out side the function?

No. they are permitted to that function only.

20. How to create global variables?

Create variables outside function.

Questions 11 - 20

Interview Questions on JQuery

1. What is the difference b/w javascript and jquery?

Javascript is a programming language whereas jQuery is a framework to help make writing in
javascript easier. It's particularly useful for simply traversing the DOM in an HTML

2. Is JQuery server side scripting language?

No.

3. What is extension of jquery files and how to link it in html?

.js  they are  javascript files.

4. Where can we write jquery code?

Any where. 
Inside <head></head> or 
<body></body> or
<div></div>

5. Write a jquery code to pop up alert box?

alert(‘alert text goes here’);

6. Can we write javascript code in jquery?

Yes.

7. How to add styles to particular html element?

$(‘element’).css(‘propertyname,vaule);
Ex :- $(‘.container).css(‘color’,’#333’);

8. How to get html code of div?

$( "element" ).html();
$( "div.demo-container" ).html();

9. How to change the content of particular div element?

$( "element" ).text(content_string1);
Ex:- $( ".container" ).text(string1);

10. How to append the content to particular div element?

$(selector).append(content_string1);

Questions 01 - 10