Tuesday, November 5, 2013

oDesk Knowledge of jQuery 1.3.2 Skills Test Answers

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


The height function returns the height of an element in ________.
a. pixel unit


offset function gets the current offset of the first matched element in pixels relative to the ________.

a. document


Consider the following code snippet:
$.map(array1, function1);

Which of the following arguments is/are valid arguments of function1?
d. a and b


Which of the following statements returns all https anchor links?
a. $('a[href^=https]');


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

The above code snippet will ________.
a. animate the tag with id1 from the current width to 80% width.


How or Where can we declare a plugin so that the plugin methods are available for our script?
a. In the head of the document, include the plugin after main jQuery source file, before our script file.


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?
c. The current div tag of the iteration


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


Which of the following arguments is/are (a) valid argument(s) of fadeIn function?
e. a and c


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?
d. a, b and c


Which of the following methods can be used to utilize animate function with backgroundColor style property?
b. There is no need to do anything as jquery core already supports that style property.


Read the following JavaScript code snippet:
$('div#id1').bind('click.divClick', function () {alert('A div was clicked');});

What is divClick in the code snippet?
d. A namespace.


Which of the following values is/are valid value(s) of secondArgument in addClass('turnRed', secondArgument); function, if we use jQuery UI library?
a. 'fast'
d. 3000


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

The statement adds class border to ________.
a. all div tags and p tags in div tags


Which of the following functions can be used to attach event handler to an element?
a. bind


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


The hide() function hides an element by ________.
a. setting "display" inline style attribute of that element to "none".


is() function ________ the current selection against an expression.
a. checks


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?
c. $('#id1').fadeOut('fast', function() {$('#id2').fadeIn('slow')});


If you include jQuery after other library, how do you disable the use of $ as a shortcut for jQuery?
a. By calling jQuery.noConflict(); right after including jQuery.


Consider the following code snippet:
var message = 'Message';
$('#id1').bind('click', {msg: message}, function(event) {
alert(event.data.msg);
});
message = 'New message';
$('#id2').bind('click', {msg: message}, function(event) {
alert(event.data.msg);
});

What does the alert box display if you click on "id1"?
a. Message


Consider the following code snippet:
$('#button1').bind('click', function(data) {...});

What is the data argument?
b. Function's data


Which of the following statements select(s) all option elements that are selected?
d. a and c


Inner Height function returns the inner height of an element, ________ the border and ________ the padding.
a. excludes, includes   


Which of the following statements return(s) a set of p tags that contain "jQuery"?
d. a and b


jQuery allows you to use ________ function to switch between showing and hiding an element.
d. toggle


Consider the following code snippet:
Div 2

Which of the following tags is/are in the result of $('#id2').parents();?
d. a and c


Which of the following functions can be used to bind an event handler to display a message when the window is closed, reloaded or navigated to another page?
c. unload


each is a generic ________ function.
a. comparator


$('ul#myId > li');

What does the above statement return?
d. A set of li tags which are children of ul tags that have "myId" id.


Which of the following commands creates a basic dialog containing this code snippet «font size=2»«div id="id1"»Simple dialog«/div»«/font» using jQuery UI?
a. $('#id1).dialog();


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


What is the difference between $('p').insertBefore(arg1) and $('p').before(arg2) statement?
a. The former inserts p tags before the tags specified by arg1, the latter inserts content specified by arg2 before all p tags.


$.grep(array1, function1);

The above statement ________ the elements of array1 array which satisfy function1 function.
d. finds


Consider the following code snippet:
var message = 'Message';
$('#id1').bind('click', function() {
    alert(message);
});
message = 'New message';
$('#id2').bind('click', function() {
    alert(message);
});

What does the alert box display if you click on "id1"?
a. Message


Which of the following statements uses a valid selector?
d. a, b and c


Consider the following code snippet:



  • Items 1



  • Items 2



  • Items 3

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


    Which of the following functions will return an empty set when end() function is chained right after that function?
    c. filter


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


    The outer height is returned by outerHeight function including ________ and ________ by default.
    a. border, padding


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

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


    Consider the following code snippet:
    $('span.item').each(function (index) {
        $(this).wrap('«li»Item«/li»');
    });

    What does this code snippet do?
    a. Wraps each span tag that has class item within a li tag.


    Which of the following values is/are valid argument(s) of eq() function?
    a. 1


    Which of the following methods can be used to delete a specified tag?
    a. remove.


    Which of the following statements returns the number of matched elements of $('.class1')?
    a. $('.class1').size();


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


    If you include jQuery before another library, how do you avoid conflict between jQuery and that library?
    a. By calling jQuery.noConflict(); right after including jQuery.


    Consider the following code snippet:
    $('#ul1 li').live('click', function1);
    $('#ul1').after('


  • Last item
  • ');

    Is function1 executed if "lastLi" is clicked?
    b. No


    Which of the following methods can be used to load data?
    a. getJSON.
    b. get.


    Which of the following functions moves p tags that have para class to div with content id?
    a. function moveElement() {
            $('p.para').each(function(index) {
                $(this).appendTo('#content');
            });
        }


    Which of the following events can be used to disable right click contextual menu?
    a. contextmenu


    Which of the following functions can be used to stop event propagation?
    a. stopPropagation


    Assume that you need to build a function that manipulates an image when the image is loaded. Which of the following functions should you use?
    b. load


    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 ________.
    b. first height animation, then width animation


    jQuery allows simulating an event to execute an event handler as if that event has just occurred by using ________.
    a. trigger function


    What is the result of NaN == NaN?
    b. false


    The css() function allows you to ________.
    d. change the inline style attribute of an element.


    What is the result of the following code snippet?
    jQuery.unique([1, 2, 2, 3, 3, 1]);
    e. None of the above


    Consider the following code snippet:



    • Items 1



    • Items 2



    • Items 3

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


      Is the following code snippet a valid ajax request?
      $.ajax({data: {'name': 'jQuery'},});
      a. Yes.


      Consider the following code snippet:
          
          

      What does the alert box display when the function submitForm1 is called?
      a. email=


      Which of the following statements return(s) a set of even rows?
      e. b and c


      One advantage of $.ajax function over $.get or $.post is that ________.
      a. $.ajax offers error callback option.


      Consider the following code snippet:
      $('#table1').find('tr').hide().slice(10, 20).show();

      What is the result of this code snippet?
      a. Showing table1's rows from 11th to 20th.


      Consider the following code snippet:
      $('#div1').html($('#div1').html().replace(/bad/, " "));

      Which of the following is the result of this code snippet?
      a. Replacing "bad" word in the inner html of div1.


      Which of the following methods can be used to copy element?
      a. clone.


      Consider the following code snippet:
      $('#table1 tr:odd').addClass('oddRow');
      $('#table1 tr:even').addClass('evenRow');

      The result of the above code snippet is ________.
      a. the odd rows of table1 have evenRow class, while the even rows have oddRow class


      Consider the following code snippet:
      $('#id1').animate({width:"240px"}, "slow").animate({height:"320px"}, "fast");

      The order of the animations of this code snippet is:
      a. first width animation, then height animation


      Consider the following code snippet:
      ajaxStart(function1);

      The function1 will be executed when ________.
      c. any ajax request starts and there is no active ajax request.


      position function gets the ________ positions of an element that are relative to its offset parent.
      a. top and left


      Which of the following code snippets insert(s) the code snippet
      at the end of div tags?
      a. $('div').append('
      ');


      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 ________.
      a. the rows of table1 at order 3n + 1 (n = 0, 1, 2,...) have class firstRowClass


      $.merge(array1, array2);

      The above function merges ________.
      b. array2 into array1.


      Consider the following code snippet:
      Div 2

      Which of the following tags is/are in the result of $('#id2').parents();?
      d. a and c


      $.extend(false, object0, object1, object2);

      What does the above do?
      a. Extends the object0 by merging object1 and object2 with object0.


      Consider the following code snippet:
        function function1() {
          alert(arguments.length);
        }

      Which of the following is true when you run function1();?
      d. The alert box displays 0.

      What does $('tr:nth-child(4)') return?
      a. A set of the fourth rows of the tables.


      Is it true that we have to place the result of jQuery.getScript between tags in order to use the loaded script?
      b. No.

      Consider the following code snippet:
      $('span.item').each(function (index) {
          $(this).wrap('


    • Item
    • ');
      });

      What does this code snippet do?
      a. Wraps each span tag that has class item within a li tag.


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

      The statement adds class border to ________.
      a. all div tags and p tags in div tags


      Which of the following commands creates a basic dialog containing this code snippet
      Simple dialog
      using jQuery UI?
      a. $("#id1").dialog();


      Consider the following code snippet:
         


      • Items 1
      •  


      • Items 2
      •  


      • Items 3

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


        Consider the following code snippet:
        $('span.item').each(function (index) {
            $(this).wrap('


      • Item
      • ');
        });

        What does this code snippet do?
        d. Replaces each span tag that has class item with a


      • Item
      • .

        Which of the following seems to be correct for ajaxStart(function()) method as shown in the below Code snippet?

        $("#div1").ajaxStart(function())
        c. Method Attaches a function to be executed whenever an AJAX request begins and there is none already activated.


        Consider the following code snippet:
        $('span.item').each(function (index) {
            $(this).wrap('


      • Item
      • ');
        });

        What does this code snippet do?
        a. Wraps each span tag that has class item within a li tag.


        Which of the following code snippets insert(s) the code snippet
        at the end of div tags?
        a. $('div').append('
            footer
        d. $('
            footer
            ').appendTo('div');


        Consider the following code snippet:
            
            

        What does the alert box display when the function submitForm1 is called?
        a. email=


        Which of the following functions moves p tags that have para class to div with content id?
        c. function moveElement() {
                $('p.para').each(function(index) {
                    $(this).insertAfter('#content');
                });
            }


        Consider the following code snippet:
        function function1()
        {
           alert(arguments.length);
        }

        Which of the following is true when you run function1();?
        d. The alert box displays 0.


        How can an Ajax Request that has not yet received the response, be canceled or aborted?
        a. //xhr is ajax variable


        Which of the following is the correct way to get a Value of selected dropdownlist in jQuery without using the selected value?
        a. $("#yourdropdownid option:selected").text();


        Which of the following is the correct way to get the current URL in jQuery?
        b. $(location).attr('href');


        Which of the following is the correct way to do the following javascript Code with jQuery? var d = document; var odv = d.createElement("div"); odv.style.display = "none"; this.OuterDiv = odv; var t = d.createElement("table"); t.cellSpacing = 0; t.className = "text"; odv.appendChild(t);

        a. this.$OuterDiv = $('
            ')
            .hide()
            .append($('
            ‘)

            .attr({ cellSpacing : 0 })
            .addClass("text")
            );


        Which of the following is the correct way to select all the elements with JQuery from html that have the two classes a and b?
        a. $('.a.b')


        When the user clicks the image, a little popup is given to add some notes to the data. How can the input-image's event handler be disable if a zero is entered into the text box?
        a. $('#myimage').off('click.mynamespace');


        Which of the following is the correct way to Hide menu div by clicking outside the menu div?
        c. $(document).click(function(event) { 
            if($(event.target).parents().index($('#menucontainer')) == -1) {
            if($('#menucontainer').is(":visible")) {
            $('#menucontainer').hide()
            }
            } 
            })