Elance jQuery Test Answers
How is jQuery licensed?
Open source
What does this code do: $('#id1').animate({width:"250px"}, "slow").animate({height:"250px"}, "fast");
First the width animates, then the height animates.
Which part of the following statement is the action? $('p').css('color','blue');
.CSS
Which of the following statements will display an alert dialog when the button with id "myBtn" is clicked on?
$("#myBtn").click( function() { alert("hello"); } );
How would you hide the following element ? <input id="id_txt" name="txt" type="text" value="" />
$("#id_txt").hide();
Which of the following is valid?
$('p').css('color', 'red');
Where does jQuery code run?
client browser
Which of the following is the correct command to fade in an element over a three-second time period?
fadeIn(3000)
What is jQuery used for?
All of these
Which selector matches all elements?
*
What is the proper way to show an element?
$('#foo').show();
Which function does jQuery provide to remove whitespace from the beginning and end of a string?
$.trim( )
What does $("div.intro") select?
All div elements with class="intro"
Which is an example of chaining a jQuery command?
$("#box").fadeOut().fadeIn();
To dynamically set the src attribute of all img elements use:
$('img').attr('src', 'photo.jpg');
code for making all div elements 100 pixels high?
$("div").height(100)
Is this a valid statement in jQuery? $("#foo").hide().show().css("color", "red").fadeOut();
Yes
When using jQuery animation, you can specify duration in the following format:
All of these
How do you fetch the first span on the page which has the class 'white'?
$('span.white:first')
Which jQuery function is used to prevent code from running, before the document is finished loading?
$(document).ready()
How do you pass options to a plugin?
$("...").foobar({ option1: 123, option2: 9 });
What jQuery function is used to set an element's markup content?
.html()
What is the correct way to check if an element has a specific class?
$("#foo").hasClass("bar");
The following code is an example of ______: $('.tooltip').hide().fadeIn(9000).delay(1000).fade0ut(9000);
Chaining
Which jQuery method is used to perform an asynchronous HTTP request?
jQuery.ajax()
What does the animate method do?
Allows you to animate CSS property controlled by a numeric value
Which of the following is used to schedule a function to execute after an animation has completed?
callback function
What is the END STATE STYLE of the paragraph element in the code $('p').hide(); ?
display: none;
if you want to change the text displayed in a paragraph by adding text before what's currently displayed, which would be correct?
$('p').prepend('text to add');
What jQuery function is used to add HTML content just outside of a selection?
after()
What character is used to identify a child combinator relationship?
right carat (>)
How do you clear the contents of this paragraph element? <div id='file'><p>content goes here</p></div>
$('#file p').empty();
How should your JQuery code be wrapped so it executes only once the page has loaded?
$(document).ready(function () { /* Code goes here */ });
Which of the following selectors is the fastest?
$('#container');
What method is used to set one or more style properties for selected elements?
css()
Which of the following statement best described the following code snippet: $('#myID').animate({width:"90%"}, "fast");
Animate the tag with myID from the current width to 90% width.
Which of the following does jQuery NOT integrate seamlessly with?
JAVA
How would you prevent the default browser action from an event handler without affecting other properties of the event flow?
$a.click(function (e) { /* code */ e.preventDefault(); });
Which is a state selector?
$(':name')
True or False : It is possible to use relative values for jQuery animate() method.
True
In the following statement, which is the selector? $('p').css('color','blue');
p
What method is the primary means of attaching a handler to an event?
.on()
What can be used to append a new paragraph element into a div with id 'mydiv'?
$("<p>Paragraph</p>").appendTo("div#mydiv");
The "hide()" function set which of the following properties?
The "display" property
True or False? live() method has been removed from version 1.9
True
jQuery.trim() function is used to ?
Remove Whitespace from beginning & ending of string
$.foo() is equivalent to:
jQuery.foo()
What does every selector expression return?
jQuery object
Which of the following is NOT a valid example of a selector filter?
div:left
How do you schedule a Javascript function to execute as soon as the document has been interpreted by the browser?
.ready()
True or False : jQuery method fadeTo() permits fading to a given opacity.
True
How do you change the CSS property 'color' of an element?
$("#someID").css("color","red");
With jQuery, look at the following selector: $("div.intro"). What does it select?
All div elements with class="intro"
What does the $.get() jQuery function do?
It fires a GET AJAX request
You can copy an element by calling which of the following methods?
clone()
What does the following code do? $('#mydiv').wrap('<div/>');
Create a parent 'div' tag for element id 'mydiv'.
What is the equivalent of the following code? $('div').click(function {alert(1);});
$('div').bind('click',function {alert(1);});
Which method is used to bind an event handler to existing and future matching elements?
The selector :disabled will perform the following:
Select only elements in a disabled state
Which selector will only return one element?
:nth-child()
What does the greater sign (>) indicate in the following code? $('#summary > div').hide();
child selector
What does $("div#intro .head") select?
All elements with class="head" inside the first div element with id="intro"
What is the difference between remove() & empty()
remove() method removes the selected element(s) and its child elements whereas empty() method removes the child elements of the selected element(s)
Which of the following jQuery functions are deprecated?
All of these
Which of the following statement returns all anchor links that start with "https"?
$('a[href^="https"]');
What method returns control of the $ identifier to other libraries?
.noConflict()
What does $('#myDiv').load('page.html') do?
it fires an AJAX request, fetches the result of page.html as text, and inserts it into the div
Why do we add the stop() function before the animate() function?
stop() ends any currently running animations on the element.
Which term is given to the jQuery feature that allows the attachment of one function to another?
chaining
What is not a an AjaxEvent.
.ajaxRun()
The insertAfter function adds a new element as a sibling. What comparable function adds a new element as a child?
appendTo
What is the output of the following: $.each([1,2,3], function(){ document.write(this + 1); });
"234"
Which function locates elements at the same level as the current selection?
.siblings()
What does the following code do: $('#myDiv').trigger('click');
It simulates a click on the element and runs all the event handlers associated with it.
which jQuery method can be used to bind both the mouseover and the mouseout events?
hover()
$(function(){ //executable code }); The executable code will be run:
after the DOM has loaded, but prior to anything else loading
What keyword can be used to refer to the element that triggered the event (in the event handler callback)?
this
What term refers to the acceleration and deceleration that occurs during an animation?
easing
When an event is triggered on an element, the same event is also triggered on all of that element’s ancestors. What is the name of this process?
event bubbling
What method selects the sibling element that immediately follows the current one?
next()
What method checks for the presence of a class before applying or removing it?
.toggleClass()
How to Remove from the queue all items that have not yet been run in jquery?
clearQueue()
The "complete" callback in a jQuery AJAX request, is called only after...
the AJAX request finishes, irrespective of error or success
Given the following HTML code snippet: <div id="wrapper"> <div class="wText">...</div> ...<!-- more wText items here --> <div class="wImg">...</div> ...<!-- more wImg items here --> <div class="wVideo">...</div> ...<!-- more wVideo items here --> </div> How would you get a collection of all the items inside the "wrapper"?
$('#wrapper').children();
What element type can you apply the "jQuery.unique(...)" on?
Arrays of DOM elements
What is $(fn); a shortcut for?
$(document).ready(fn);
var result = $("#div").css("color","red") What does the "result" var contain?
jQuery object
For best performance in modern browsers, which of the following would you use to select all radio inputs?
$(‘[type=”radio”]’);
Which of these is NOT a pseudoclass?
:next
how do you select the content document of an iframe on the same domain jQuery
.contents()
By default, the outerWidth(true) function returns the width of the element including
margin,border and padding
How to set default options for all future AJAX requests?
jQuery.ajaxSetup( options )
Which of the following selectors is NOT equivalent to the others?
:first
True or False? jQuery UI is part of jQuery.
False
What does the empty() function do?
Removes all child nodes of the set of matched elements from the DOM
Which of the following is NOT a custom jQuery form selector?
:form
Which of the following will get the CURRENT COORDINATES of the first element in the set of matched elements, RELATIVE TO THE DOCUMENT?
offset()
How do I pull a native DOM element from a jQuery object?
$( "#foo" ).get( 0 );
What does the following code do? $(".foobar").find(".foo").fadeOut();
Fade out of elements matching ".foo" that are descendants of elements matching ".foobar"
What does the filter() method do in this: $('div').filter('.nav')
it sifts through all the divs and leaves only those with the nav class
$(".clicker").click(function() { $('link[rel=stylesheet]').attr('href' , $(this).attr('rel')); }); The above is used to do what?
Change the stylesheet loaded in the page upon clicking the element with class "clicker"
<div id="MyDiv">Two</div> <div id="MyDiv">One</div> <div id="MyDiv">Five</div> Given the above HTML What would the output of the following code be? var myDivText = $('#MyDiv').text() console.log(myDivText)
Two
Which can be used to detect broken images?
$("img").error(callbackFunction)
What method allows us to remove values that were previously set using jQuery.data()?
.removeData()
What is the difference between $('#element').remove() and $('#element').detach()
remove() removes the element from the DOM along with any jQuery data, while detach() only removes the element from the DOM.
What is the name of a function that intercepts combinations of user actions?
compound event handler
What index value does the :nth-child() selector starts with?
1
How can you get the number of paragraphs in the html document using jQuery?
$('p').length
Which custom selector is case sensitive?
:contains()
True or False: .position() accepts an optional argument as a selector
False
What does this return: $(".class").attr("id");
The value of the 'id' attribute for the first element in the set of matched elements
How do you get the value of the selected radio button in a group of radio buttons with the name of 'radioName'?
$('input[name=radioName]:checked', '#myForm').val()
What does the serialize() method do: $('#myForm').serialize();
fetches the names and values of all the input fields contained in the form, and generates a URL encoded string representation
What will be the value of "display" css property of the following tag? $('span').hide(); $('span').show();
It will vary depending the value of the span's initial display property
Which is not a type of selector?
Javascript Selector
Which will NOT select the second "li" element?
$( "li:eq( 2 )" )
Event delegation:
Allows you to register handlers before elements are added to the page
What is an event handler?
A function that executes your code after the event occurs.
Which of the following syntaxes are equivalent to $(document).ready(handler)?
$(handler)
Which jQuery method animates the height of matched elements?
.slideToggle()
What does this do? $("p").find("span").end().css("border", "2px red solid");
Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs, then apply CSS rule.
Which of the following will get the current coordinates (of the first element in the jQuery collection) relative to the offset parent?
position()
What do you use jQuery.noConflict() for?
to restore the '$' to its previous owner.
What does the ".divClick" code snippet refers to in the following code snippet: $('div#id1').bind('click.divClick', function () {alert('A div was clicked');});
A namespace
Attribute Contains Prefix Selector is:
[name|="value"]
$("[id|=experience]") will select which ID?
<div id="experience-51">
How can you add your own custom selectors to jQuery?
$.extend($.expr[':'], { name : function }); or $.expr[':'].name = function(){}
What does .delegate() allow you do, that .live() does not?
Attach the event handler to any DOM element.
Which of these is NOT a valid way to initiate the document.ready call?
jQuery(document).ready(function($) { /* Stuff here */ })(jQuery);
What selector engine does jQuery use
Sizzle
In what scenario will the alert box show? $(function(){ if(!$("p")) alert("hello"); });
It will never show.
What does the following return? $.inArray("foo", ["foo", "bar"]);
0
What method is used to switch between adding/removing one or more classes (for CSS) from selected elements?
toggleClass()
Which of the following methods can be used to remove the title of an img element?
$("img").removeAttr("title")
What keyword would you use to refer to the object on which the currently executing method has been invoked?
this
What is the difference between searching 'find()' and 'children()'
The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.
How do you delete an element with an id of "dialog" from the DOM using jQuery?
$("#dialog").remove();
How do you test if an element has a specific class?
use .hasClass()
Which of the following is correct?
jQuery is a JavaScript Library
What function can be used to alternate an element's state between display and hidden?
toggle
Which is a syntactically valid jQuery command?
$("#book").fadeOut();
jQuery uses CSS selectors to select elements?
True
Illustrate selecting a HTML element using its class:
$(".myClass")
Open source
What does this code do: $('#id1').animate({width:"250px"}, "slow").animate({height:"250px"}, "fast");
First the width animates, then the height animates.
Which part of the following statement is the action? $('p').css('color','blue');
.CSS
Which of the following statements will display an alert dialog when the button with id "myBtn" is clicked on?
$("#myBtn").click( function() { alert("hello"); } );
How would you hide the following element ? <input id="id_txt" name="txt" type="text" value="" />
$("#id_txt").hide();
Which of the following is valid?
$('p').css('color', 'red');
Where does jQuery code run?
client browser
Which of the following is the correct command to fade in an element over a three-second time period?
fadeIn(3000)
What is jQuery used for?
All of these
Which selector matches all elements?
*
What is the proper way to show an element?
$('#foo').show();
Which function does jQuery provide to remove whitespace from the beginning and end of a string?
$.trim( )
What does $("div.intro") select?
All div elements with class="intro"
Which is an example of chaining a jQuery command?
$("#box").fadeOut().fadeIn();
To dynamically set the src attribute of all img elements use:
$('img').attr('src', 'photo.jpg');
code for making all div elements 100 pixels high?
$("div").height(100)
Is this a valid statement in jQuery? $("#foo").hide().show().css("color", "red").fadeOut();
Yes
When using jQuery animation, you can specify duration in the following format:
All of these
How do you fetch the first span on the page which has the class 'white'?
$('span.white:first')
Which jQuery function is used to prevent code from running, before the document is finished loading?
$(document).ready()
How do you pass options to a plugin?
$("...").foobar({ option1: 123, option2: 9 });
What jQuery function is used to set an element's markup content?
.html()
What is the correct way to check if an element has a specific class?
$("#foo").hasClass("bar");
The following code is an example of ______: $('.tooltip').hide().fadeIn(9000).delay(1000).fade0ut(9000);
Chaining
Which jQuery method is used to perform an asynchronous HTTP request?
jQuery.ajax()
What does the animate method do?
Allows you to animate CSS property controlled by a numeric value
Which of the following is used to schedule a function to execute after an animation has completed?
callback function
What is the END STATE STYLE of the paragraph element in the code $('p').hide(); ?
display: none;
if you want to change the text displayed in a paragraph by adding text before what's currently displayed, which would be correct?
$('p').prepend('text to add');
What jQuery function is used to add HTML content just outside of a selection?
after()
What character is used to identify a child combinator relationship?
right carat (>)
How do you clear the contents of this paragraph element? <div id='file'><p>content goes here</p></div>
$('#file p').empty();
How should your JQuery code be wrapped so it executes only once the page has loaded?
$(document).ready(function () { /* Code goes here */ });
Which of the following selectors is the fastest?
$('#container');
What method is used to set one or more style properties for selected elements?
css()
Which of the following statement best described the following code snippet: $('#myID').animate({width:"90%"}, "fast");
Animate the tag with myID from the current width to 90% width.
Which of the following does jQuery NOT integrate seamlessly with?
JAVA
How would you prevent the default browser action from an event handler without affecting other properties of the event flow?
$a.click(function (e) { /* code */ e.preventDefault(); });
Which is a state selector?
$(':name')
True or False : It is possible to use relative values for jQuery animate() method.
True
In the following statement, which is the selector? $('p').css('color','blue');
p
What method is the primary means of attaching a handler to an event?
.on()
What can be used to append a new paragraph element into a div with id 'mydiv'?
$("<p>Paragraph</p>").appendTo("div#mydiv");
The "hide()" function set which of the following properties?
The "display" property
True or False? live() method has been removed from version 1.9
True
jQuery.trim() function is used to ?
Remove Whitespace from beginning & ending of string
$.foo() is equivalent to:
jQuery.foo()
What does every selector expression return?
jQuery object
Which of the following is NOT a valid example of a selector filter?
div:left
How do you schedule a Javascript function to execute as soon as the document has been interpreted by the browser?
.ready()
True or False : jQuery method fadeTo() permits fading to a given opacity.
True
How do you change the CSS property 'color' of an element?
$("#someID").css("color","red");
With jQuery, look at the following selector: $("div.intro"). What does it select?
All div elements with class="intro"
What does the $.get() jQuery function do?
It fires a GET AJAX request
You can copy an element by calling which of the following methods?
clone()
What does the following code do? $('#mydiv').wrap('<div/>');
Create a parent 'div' tag for element id 'mydiv'.
What is the equivalent of the following code? $('div').click(function {alert(1);});
$('div').bind('click',function {alert(1);});
Which method is used to bind an event handler to existing and future matching elements?
The selector :disabled will perform the following:
Select only elements in a disabled state
Which selector will only return one element?
:nth-child()
What does the greater sign (>) indicate in the following code? $('#summary > div').hide();
child selector
What does $("div#intro .head") select?
All elements with class="head" inside the first div element with id="intro"
What is the difference between remove() & empty()
remove() method removes the selected element(s) and its child elements whereas empty() method removes the child elements of the selected element(s)
Which of the following jQuery functions are deprecated?
All of these
Which of the following statement returns all anchor links that start with "https"?
$('a[href^="https"]');
What method returns control of the $ identifier to other libraries?
.noConflict()
What does $('#myDiv').load('page.html') do?
it fires an AJAX request, fetches the result of page.html as text, and inserts it into the div
Why do we add the stop() function before the animate() function?
stop() ends any currently running animations on the element.
Which term is given to the jQuery feature that allows the attachment of one function to another?
chaining
What is not a an AjaxEvent.
.ajaxRun()
The insertAfter function adds a new element as a sibling. What comparable function adds a new element as a child?
appendTo
What is the output of the following: $.each([1,2,3], function(){ document.write(this + 1); });
"234"
Which function locates elements at the same level as the current selection?
.siblings()
What does the following code do: $('#myDiv').trigger('click');
It simulates a click on the element and runs all the event handlers associated with it.
which jQuery method can be used to bind both the mouseover and the mouseout events?
hover()
$(function(){ //executable code }); The executable code will be run:
after the DOM has loaded, but prior to anything else loading
What keyword can be used to refer to the element that triggered the event (in the event handler callback)?
this
What term refers to the acceleration and deceleration that occurs during an animation?
easing
When an event is triggered on an element, the same event is also triggered on all of that element’s ancestors. What is the name of this process?
event bubbling
What method selects the sibling element that immediately follows the current one?
next()
What method checks for the presence of a class before applying or removing it?
.toggleClass()
How to Remove from the queue all items that have not yet been run in jquery?
clearQueue()
The "complete" callback in a jQuery AJAX request, is called only after...
the AJAX request finishes, irrespective of error or success
Given the following HTML code snippet: <div id="wrapper"> <div class="wText">...</div> ...<!-- more wText items here --> <div class="wImg">...</div> ...<!-- more wImg items here --> <div class="wVideo">...</div> ...<!-- more wVideo items here --> </div> How would you get a collection of all the items inside the "wrapper"?
$('#wrapper').children();
What element type can you apply the "jQuery.unique(...)" on?
Arrays of DOM elements
What is $(fn); a shortcut for?
$(document).ready(fn);
var result = $("#div").css("color","red") What does the "result" var contain?
jQuery object
For best performance in modern browsers, which of the following would you use to select all radio inputs?
$(‘[type=”radio”]’);
Which of these is NOT a pseudoclass?
:next
how do you select the content document of an iframe on the same domain jQuery
.contents()
By default, the outerWidth(true) function returns the width of the element including
margin,border and padding
How to set default options for all future AJAX requests?
jQuery.ajaxSetup( options )
Which of the following selectors is NOT equivalent to the others?
:first
True or False? jQuery UI is part of jQuery.
False
What does the empty() function do?
Removes all child nodes of the set of matched elements from the DOM
Which of the following is NOT a custom jQuery form selector?
:form
Which of the following will get the CURRENT COORDINATES of the first element in the set of matched elements, RELATIVE TO THE DOCUMENT?
offset()
How do I pull a native DOM element from a jQuery object?
$( "#foo" ).get( 0 );
What does the following code do? $(".foobar").find(".foo").fadeOut();
Fade out of elements matching ".foo" that are descendants of elements matching ".foobar"
What does the filter() method do in this: $('div').filter('.nav')
it sifts through all the divs and leaves only those with the nav class
$(".clicker").click(function() { $('link[rel=stylesheet]').attr('href' , $(this).attr('rel')); }); The above is used to do what?
Change the stylesheet loaded in the page upon clicking the element with class "clicker"
<div id="MyDiv">Two</div> <div id="MyDiv">One</div> <div id="MyDiv">Five</div> Given the above HTML What would the output of the following code be? var myDivText = $('#MyDiv').text() console.log(myDivText)
Two
Which can be used to detect broken images?
$("img").error(callbackFunction)
What method allows us to remove values that were previously set using jQuery.data()?
.removeData()
What is the difference between $('#element').remove() and $('#element').detach()
remove() removes the element from the DOM along with any jQuery data, while detach() only removes the element from the DOM.
What is the name of a function that intercepts combinations of user actions?
compound event handler
What index value does the :nth-child() selector starts with?
1
How can you get the number of paragraphs in the html document using jQuery?
$('p').length
Which custom selector is case sensitive?
:contains()
True or False: .position() accepts an optional argument as a selector
False
What does this return: $(".class").attr("id");
The value of the 'id' attribute for the first element in the set of matched elements
How do you get the value of the selected radio button in a group of radio buttons with the name of 'radioName'?
$('input[name=radioName]:checked', '#myForm').val()
What does the serialize() method do: $('#myForm').serialize();
fetches the names and values of all the input fields contained in the form, and generates a URL encoded string representation
What will be the value of "display" css property of the following tag? $('span').hide(); $('span').show();
It will vary depending the value of the span's initial display property
Which is not a type of selector?
Javascript Selector
Which will NOT select the second "li" element?
$( "li:eq( 2 )" )
Event delegation:
Allows you to register handlers before elements are added to the page
What is an event handler?
A function that executes your code after the event occurs.
Which of the following syntaxes are equivalent to $(document).ready(handler)?
$(handler)
Which jQuery method animates the height of matched elements?
.slideToggle()
What does this do? $("p").find("span").end().css("border", "2px red solid");
Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs, then apply CSS rule.
Which of the following will get the current coordinates (of the first element in the jQuery collection) relative to the offset parent?
position()
What do you use jQuery.noConflict() for?
to restore the '$' to its previous owner.
What does the ".divClick" code snippet refers to in the following code snippet: $('div#id1').bind('click.divClick', function () {alert('A div was clicked');});
A namespace
Attribute Contains Prefix Selector is:
[name|="value"]
$("[id|=experience]") will select which ID?
<div id="experience-51">
How can you add your own custom selectors to jQuery?
$.extend($.expr[':'], { name : function }); or $.expr[':'].name = function(){}
What does .delegate() allow you do, that .live() does not?
Attach the event handler to any DOM element.
Which of these is NOT a valid way to initiate the document.ready call?
jQuery(document).ready(function($) { /* Stuff here */ })(jQuery);
What selector engine does jQuery use
Sizzle
In what scenario will the alert box show? $(function(){ if(!$("p")) alert("hello"); });
It will never show.
What does the following return? $.inArray("foo", ["foo", "bar"]);
0
What method is used to switch between adding/removing one or more classes (for CSS) from selected elements?
toggleClass()
Which of the following methods can be used to remove the title of an img element?
$("img").removeAttr("title")
What keyword would you use to refer to the object on which the currently executing method has been invoked?
this
What is the difference between searching 'find()' and 'children()'
The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.
How do you delete an element with an id of "dialog" from the DOM using jQuery?
$("#dialog").remove();
How do you test if an element has a specific class?
use .hasClass()
Which of the following is correct?
jQuery is a JavaScript Library
What function can be used to alternate an element's state between display and hidden?
toggle
Which is a syntactically valid jQuery command?
$("#book").fadeOut();
jQuery uses CSS selectors to select elements?
True
Illustrate selecting a HTML element using its class:
$(".myClass")
Comments
Post a Comment