UpWork (oDesk) & Elance jQuery Test Question & Answers

13:14
jQuery Test Question & Answer is really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is very valueable to acquire knowledge of this skill. Lets Start test.


Ques: How can the href for a hyperlink be changed using jQuery?
Ans: $("a").attr("href", "http://www.google.com/");

Ques: The position function gets the ___ positions of an element that are relative to its offset parent.
Ans: top and left

Which of the following code snippets returns the same result as $('#id1 li').not($('#li2'));?
Ans: $('#li2').siblings();

Ques: Which of the following is the correct way to debug JavaScript/jQuery event bindings with Firebug or a similar tool?
Ans: var clickEvents = $('#foo').data("events").click; jQuery.each(clickEvents, function(key, value) { console.log(value) // prints "function() { console.log('clicked!') }" })

Ques: Which of the following events can be used to disable right click contextual menu?
Ans: contextmenu

Ques: Which of the following gets the href attribute of "id1"?
Ans:  $('#id1).attr('href');

Ques: Which of the following is the correct way to manage a redirect request after a jQuery Ajax call?
Ans: $.ajax({ type: "POST", url: reqUrl, data: reqBody, dataType: "json", success: function(data, textStatus) { if (data.redirect) { // data.redirect contains the string URL to redirect to window.location.href = data.redirect; } else { // data.form contains the HTML for the replacement form $("#myform").replaceWith(data.form); } } });

Ques: Which of the following is the correct way to change the image source during click event of a button in jQuery?
Ans: $("#button").click(function(){$(“img”).attr(); });

Ques: What is the purpose of  $(document).ready() function in Jquery?
Ans:To execute functions after DOM is loaded

Ques:  Which of the following will show an alert containing the content(s) of a database selection?
Ans: $.ajax({ type: "GET", url: "process_file.php?comp_id="+comp_id, success: function (result) { alert(result); } });

Ques:  How can an Ajax request that has not yet received a response be canceled or aborted?
Ans: //xhr is an Ajax variable xhr.abort()

Ques: Consider the following code snippet:
$('a.arrow-1').click(function () {
    $('.second-row').slideUp();
    $(this).parent('.first-row').siblings('.second-row').slideDown();
});

The order of the animations of this code snippet are:
Ans: .second-row will slide up, then the targeted parent sibling .second-row will slide down.

Ques: Consider the following code snippet:


$('#ul1 li').live('click', function1);

$('#ul1').after('<li id="lastLi">Last item</li>');


Is function1 executed if "lastLi" is clicked?
Ans: No

Ques: jQuery allows you to use ___ function to switch between showing and hiding an element.
Ans:  toggle

Ques: What does $('tr.rowClass:eq(1)'); return?
Ans: One element set which is the second row of the first table.

Ques: Which option can be used to have jQuery wait for all images to load before executing something on a page?
Ans: With jQuery, can use $(document).ready() to execute something when the DOM is loaded and$(window).load() to execute something when all other things are loaded as well, such as the images.

Ques: offset function gets the current offset of the first matched element in pixels relative to the ___.
Ans: document

Ques:  Consider the following code snippet:

$(document).ready(function() {
  $('div').each(function(index) {
    alert(this);
  });
});

Which of the following objects does the 'this' variable refer to?
Ans:  The current div tag of the iteration.

Ques:  Which of the following returns the children tags of "id1"?
Ans:  $('#id1').children();

Ques: Which of the following is the correct way to select an option based on its text in jQuery?
Ans:  $("#myselect option").filter(function(){ return $(this).text() == 'text';}).prop('selected', true);

Ques:  Consider the following code snippet:

$('#id1').animate({width:"240px"}, { queue:false, duration:1000 }).animate({height:"320px"}, "fast");

The order of the animations of this code snippet is ___.
Ans: Both the width animation and the height animation occur at the same time.

Ques:  What is the result of NaN == NaN?
Ans: false

Ques: $("div").find("p").andSelf().addClass("border");
The statement adds class border to ___.
Ans: all div tags and p tags in div tags

Ques:  $('#a1').one('click', {times: 3}, function1);

Which of the following is true for the above?
Ans: function1 will be executed once regardless of the number of times a1 is clicked.

Which of the following code snippets return(s) a set of all li tags within id1 except for the li tag with id li2?
Ans:  $('#id1 li').not($('#li2'));

Ques: Assume that you want that first the tag with "id1" fades out and then the tag with "id2" fades in. Which of the following code snippets allow(s) you to do so?
Ans:  $('#id1').fadeOut('fast', function() {$('#id2').fadeIn('slow')});

Ques: Which of the following methods can be used to copy element?
Ans: clone

Ques: $('#id1').animate({width:"80%"}, "slow")

The above code snippet will ___.
Ans: animate the tag with id1 from the current width to 80% width.

Which of the following code snippets return(s) a set of all li tags within id1 except for the li tag with id li2?
Ans:  $('#id1 li').not($('#li2'));

Ques: Which of the following methods can be used to utilize the animate function with the backgroundColor style property?
Ans: Use the jQuery UI library.

Ques: Consider the following code snippet:
$('#id1').animate({width:"240px"}, { queue:false, duration:1000 }).animate({height:"320px"}, "fast");
The order of the animations of this code snippet is ___.
Ans: Both the width animation and the height animation occur at the same time.

Ques: Which option is correct to perform a synchronous AJAX request?
Ans: beforecreate: function(node,targetNode,type,to) { jQuery.ajax({ url: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value), success: function(result) { if(result.isOk == false) alert(result.message); }, async: false }); }


Ans: $("#list option[value='2']").text();

Ques: If jQuery is included before another library, how can conflict between jQuery and that library be avoided?
Ans: By calling jQuery.noConflict(); right after including jQuery.

Ques: Which of the following functions is/are built-in jQuery regular expression function(s)?
Ans:  match

Ques: each() is a generic ___ function.
Ans: iterator

Ques: Consider the following code snippet:
$(document).ready(function1);
$(document).ready(function2);
$(document).ready(function3);
Which of the following functions are executed when DOM is ready?
Ans:  function1, function2, and function3

Ques: Which of the following represents the best way to make a custom right-click menu using jQuery?
Ans: $(document).bind("contextmenu", function(event) { event.preventDefault(); $("
Custom menu
") .appendTo("body") .css({top: event.pageY + "px", left: event.pageX + "px"}); });


Ques: Consider the following code snippet:
$('#button1').bind('click', function(data) {...});
What is the data argument?
Ans: Click event's data

Ques: $("div").find("p").andSelf().addClass("border");

The statement adds class border to ___.
Ans: all div tags and p tags in div tags

Ques: What is the result of this function: jQuery.makeArray ( true )?
Ans:  [ true ]

Ques: Which of the following is the correct way to get the value of a textbox using id in jQuery?
Ans:  $(“#textbox”).val()

Ques: The hide() function hides an element by ___.
Ans:  setting "display" inline style attribute of that element to "none".

Ques: Consider the following code snippet:

$('#table1').find('tr').filter(function(index) { return index % 3 == 0}).addClass('firstRowClass');

The result of the above code snippet is ___.
Ans: The rows of table1 at order 3n + 1 (n = 0, 1, 2,...) will belong to the class firstRowClass.

Ques: One advantage of $.ajax function over $.get or $.post is that ___
Ans: $.ajax offers error callback option.

Ques: Using an element of some kind that is being hidden using .hide() and shown via .show().  Which of the following is the best way to determine if that element is currently hidden or visible on the screen?
Ans: $(element).is(":visible")

Ques: Which of the following will get the first column of all tables using jQuery?
Ans:  $('table.tblItemTemplate td:first-child');

Ques: Which option is correct to use the below function to set cursor position for  textarea?
Function:
$.fn.selectRange = function(start, end) {
    return this.each(function() {
        if (this.setSelectionRange) {
            this.focus();
            this.setSelectionRange(start, end);
        } else if (this.createTextRange) {
            var range = this.createTextRange();
            range.collapse(true);
            range.moveEnd('character', end);
            range.moveStart('character', start);
            range.select();
        }
    });
};
Ans: $('#elem').selectRange(3,5);

Ques: Assuming that the jQuery UI library is used to make a list sortable, which of the following code snippets makes "list1" sortable?
Ans:  $('#list1').sortable();

Ques: Which of the following functions can be used to stop event propagation?
Ans: stopPropagation

Ques: How can the child img be selected inside the div with a selector?
Ans: jQuery(this).find("img");

Ques: jQuery allows simulating an event to execute an event handler as if that event has just occurred by using ___.
Ans:  trigger function

Ques: Which of the following is the correct use of ajaxStart() function?
Ans: ajaxStart() function is used to run some code when ajax call start.

Ques:  The height function returns the height of an element in ___.
Ans: pixel units

Ques: Which of the following values is/are valid value(s) of secondArgument in addClass('turnRed', secondArgument); function, if the jQuery UI library is being used?
Ans: 3000

Ques: Consider the following code snippet:


$('#button1').bind('click', function(data) {...});


What is the data argument?
Ans: Function's data

Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techtunes, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD UpWorkElanceTests ARSBD-JOBS DesignerTab UpLance

Share this

Related Posts

Previous
Next Post »

We recommend you to subscribe us to get update from your email. EmoticonEmoticon