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.