jQuery Test Upwork

How to select all element available in DOM with jQuery?

$("*")
$("?")
$("#")
$(".")

Which of the following jQuery method can be used to attach a function to be executed when all AJAX requests have ended?

ajaxStart( callback )
ajaxComplete( callback )
ajaxSend( callback )
ajaxStop( callback )

How jQuery hide() function works?

ets “visibility” inline style attribute of that element to “hidden”.
sets “display” inline style attribute of that element to “none”.
sets the horizontal attribute of that element to “-100px” off visible screen.
sets the vertical attribute of that element to “-100px” off visible screen.

Which of the following method returns all ancestors elements between a and a element?

$("span").parentsUntil("html");
$("span") .parents();
Both 1 and 2
None of the mentioned

What is the difference between the .position() and the .offset() method?

The .position() method retrieves the current position relative to the offset parent, whereas the .offset() method retrieves the current position of an element relative to the document.
The .position() method retrieves the current position relative to the document, whereas the .offset() method retrieves the current position of an element relative to the offset parent.
Both methods retrieve the current position relative to the document.

Which of the following is the correct way to create an event and trigger it artificially?

var e = jQuery.EventObject("click");
jQuery("body").trigger(e);

var e = jQuery.Event("click");
jQuery("body").call(e);

var e = jQuery.Event("click");
jQuery("body").target(e);

var e = jQuery.Event("click");
jQuery("body").trigger(e);

Which built-in method removes the element from an array and returns that element?

last
get
pop
remove
None of the above.

Which of the following code can be used to stop default form submission?

$("form").submit(function(e){
    e.preventDefault();
});

$("form").handleSubmit(function(e){
    e.preventDefault();
});

$("form").onSubmit(function(e){
    e.preventDefault();
});

$("form").catchSubmit(function(e){
    e.preventDefault();
});

Which of the following values is/are valid argument(s) of eq() function?
Note: There may be more than one right answer.

1
‘2’
-1
All are invalid

Which of the following is not a jQuery utility method?

$.trim()
$.extend()
$.ajax()

What will the following code does:
$(document).ready(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
});

show context menu on page
don't show context menu on page when right clicked.
do nothing
disable context menu links

Select the fastest and most efficient way of hiding elements:

$('#someElement p.someClass').hide();
$('#someElement’).find('p.someClass').hide();
$('#someElement p’).filter(‘:has(.someClass)’).hide();

How would you disable an HTML button element with id myButton?

$(‘#myButton’).prop(‘disabled’, true);
$(‘#myButton’).attr(‘disabled’)=true
$(‘#myButton’).attr(‘disabled’)

Which are the correct ways of listening for when the DOM is ready to be manipulated?
Note: There may be more than one right answer.

$(document).ready(function() {
    // DOM is ready
});

$(window).load(function() {
    // DOM is ready

$(function() {
    // DOM is ready
});

Which of the following is/are correct to set the src attribute of an image?
Note: There may be more than one right answer.

$("#image").attr("src", "photo.jpg");
$("#image").attrib("src", "photo.jpg");
$("#image").attr( {"src": "photo.jpg" });
$("#image").attr("img", "photo.jpg");

Please select the fastest jQuery selector example:

$(’a[data-selected=“true”] img’)
$(‘#image’)
$(‘a.selected img’)

What does the :selected selector do?

Selects all elements that are visible.
Selects all input elements of type text.
Selects all elements that are selected.
None of the mentioned.

What is the correct syntax to create a method in jQuery plugin? Assume that methodName is the name of the method and methodDefinition is the definition of the method.

jQuery.function.methodName = methodDefinition;
jQuery.fn.methodName = methodDefinition;
jQuery.fun.methodName = methodDefinition;
None of the mentioned

What is the most efficient way to load your code once DOM tree has loaded (without waiting for external resources)?

window.onload = function() {
   // your code here
};

jQuery(document).onload(function() {
    / your code here
});

jQuery(document).onready(function() {
    / your code here
});

jQuery(document).ready(function() {
    / your code here
});

How would you check if a checkbox element is checked?
Note: There may be more than one right answer.

$(‘input[type=“checkbox”]:checked’).val();
$('input[type="checkbox”]’).is(‘:checked’);
$(‘input[type=“checkbox”]’).prop(‘checked’);

Which of the following jQuery method prevents the browser from executing the default action?

preventDefault( )
stopImmediatePropagation( )
stopPropagation( )
None of the above.

Which of the following methods allow us to insert new content surrounding existing content?

.unwrap()
.wrap()
.wrapAll()
.wrapInner()
All of the mentioned

Which of the following should be placed in the code below to alert data passed to event handler?
function myHandler( event ) {
// code .. select from the options below
}
$( "#box").on( "click", { foo: "bar" } , myHandler );

alert( event.data.foo);
alert( event.foo);
alert( event.property.foo);
alert( event.object.foo);

Which of the following is not correct to animate CSS properties?

$(".header").click(function() {
    $("#box").animate({background: "red"});
});

$(".header").click(function() {
    $("#box").animate({minHeight: "200px"});
});

$(".header").click(function() {
    $("#box").animate({fontSize: "20px"});
});

$(".header").click(function() {
    $("#box").animate({letterSpacing: "2px"});
});

Which of the following jQuery selector selects elements by tag name?

$('tag')
$('#tag')
$('.tag')
None of the above

Which of the following are correct to chain your plugin?
Note: There may be more than one right answer.

(function($) {
    $.fn.helloWorld = function( customText ) {
        return this.each( function() {
            $(this).text( customText );
        });
    }

}(jQuery));
(function($) {
    $.fn.helloWorld = function() {
        return this.each( function() {
            $(this).text("Hello, World!");
        });
    }

}(jQuery));
(function($) {
    $.fn.helloWorld = function() {
        this.each( function() {
            $(this).text("Hello, World!");
        });
    }
}(jQuery));

Which of the following is/are correct to attach a click event method that handles the click event of an element?
Note: There may be more than one right answer.

$(".content h2").click(function() {
    // Code goes here
});

$(".content h2").on("click", "h2", function() {
    // Code goes here
});

$(".content").click("h2", function() {
    // Code goes here
});

$(".content h2").onclick(function() {
    // Code goes here
});

Which option allows you to select all of the s and s in a page??

$('div', 'span');
$('div, span');
$('div span');
$('div' 'span');

Which of the following statements best describes the below code:
$('span.item').each(function (index) {
    $(this).wrap('<p></p>');
});

Wraps each span tag that has class item within a p tag.
Inserts each span tag that has class item into a p tag.
Inserts Item into each span that has item class.
Replaces each span tag that has class item with a Item.

Which of the following method returns all ancestor elements between a  and a  element?

$("span").parentsUntil("html");
$("span").parents();
Both 1 and 2
None of the mentioned

Which of the following jQuery method checks whether a supplied callback is in a list?

callbacks.hasCallback(foo)
callbacks.inList(foo)
callbacks.hasMethod(foo)
callbacks.has(foo)

Which of the following is not a correct value for dataType when making Ajax request?

json
xml
sql
text

Which of the following jQuery method gets the height property of an element?

getHeight()
height()
getCssHeight()
None of the above

Which function can be used to prevent the default action of an event?

event.stopPropagation();
event.preventDefault();
event.off();
event.stopDefault();

To wrap  text in  element and give id as "title"?

$("h1").wrap("<a id='title'></a>");
$("h1").wrapInner("<a id='title'></a>");
$("h1").wrapAll("<a id='title'></a>");
$("h1").wrapInside("<a id='title'></a>");

Which of the following is correct to replace all elements that have a class named "foo" with an H2 element?
Note: There may be more than one right answer.

$("<h2></h2>").replaceAll(".foo");
$(".foo").replaceAll("<h2></h2>");
$(".foo").replaceEach("<h2></h2>");
$(".foo").replaceWith("<h2></h2>");

Which of the following jQuery method adds the previous selection to the current selection?

add( selector )
andSelf( )
append(selector)
None of the abov

What is the best method to select all the radio inputs on a page?

$(‘:radio’);
$(‘*:radio’);
$(‘input:radio’);

Which of the following is the best way to open a jQuery UI dialog box without a title bar?

$(«#ui-dialog-titlebar»).hide();
$(«.ui-dialog-titlebar»).hide();
$(«#dialog»).siblings(‘div#ui-dialog-titlebar’).remove();
$(«.ui-titlebar»).hide();

Which of the following is the correct way to get the value of a selected radio button from two radio buttons with jQuery?

$(‘input[name=radioName]:checked’, ‘#myForm’).val()
$(«form:radio:checked»).val();
$(«input[name=’radioName’]:checked»).val()
$(«form:radio:button:checked»).val();

How to represent a directed graph dynamically on an HTML page with graph layout with jQuery?

    var g = new Graph();
    g.addEdge("strawberry", "cherry");
    g.addEdge("cherry", "apple");
    g.addEdge("id34", "cherry");

    Imppossible

    var g = new Graph();
    g.addEdge("strawberry", "cherry");
    g.addVertex("cherry", "apple");
    g.addEdge("id34", "cherry");

    var g = new Graph();
    g.addVertex("strawberry", "cherry");
    g.addVertex("cherry", "apple");
    g.addVertex("id34", "cherry");

Which of the following jQuery method gets the current offset of the first matched element, in pixels, relative to the document?

offset
offsetParent
position
None of the above

Which of the following jQuery method setups default values for future AJAX requests?

jQuery.ajax( options )
jQuery.ajaxSetup( options )
serialize( )
serializeArray(

Which jQuery method serializes a set of input elements into a string of data

serializeArray( )
serialize( )
jQuery.ajaxSetup( options )
jQuery.ajax( options )

Which  jQuery method retrieves all the elements contained in the jQuery set, as an array?

toArray()
toArrayObject()
changeToArray()
changeToArray(

Which jQuery method gets the combined text contents of an element?

getText()
text()
getHtml()
getContent()

What does the event.stopPropagation() function does?

Bubbles up the DOM tree and stops at the closest parent element.
Bubbles up the DOM tree, preventing any parent handlers from being notified of the event.
Bubbles up the DOM and prevents other handlers on the same element from running.
None of the above.

Select the recommended way of calling multiple functions one after another on an element:

$(‘#someElement’).hide();
$(‘#someElement’).html(‘Hide!’);
$(‘#someElement’).customFunction();

$(‘#someElement’).hide().html(‘Hide!’).customFunction();

var someElement = $(‘#someElement’);
someElement.hide();
someElement.html('Hide!');
someElement.otherStuff();

Which is the correct method to remove a property for the set of matched element?

.removeProp()
.removeProperties()
.moveProp()
None of the above

How would you check if an HTML element with an id of someElement exists in the DOM?

if ($(‘#someElement’).is(‘:visible’) == ‘true’)
if ($(‘#someElement’).length)
if ($(‘#someElement’).exists())
None of the above

How can the href a hyperlink be changed using jQuery?

$("a").link("http://www.google.com/");
$("a").change("href","http://www.google.com/");
$("a").link("href","http://www.google.com/");
$("a").attr("href", "http://www.google.com/");

The position function gets the ___ positions of an element that are relative to its offset parent.

top and left
top and right
bottom and left
bottom and right

What is the purpose of  $(document).ready() function in Jquery?

To execute functions after all content and images are loaded
To execute functions after DOM is loaded
To execute functions before DOM load
To execute functions before content and images load

Which of the following code snippets insert(s) the code snippet <font size=2><div class="footer">footer</div></font> at the end of div tags?

$('div').append('<div class="footer">footer</div>');
$('div').appendTo('<div class="footer">footer</div>');
$('<div class="footer">footer</div>').append('div');
$('<div class="footer">footer</div>').appendTo('div');

What does $('tr.rowClass:eq(1)'); return?

One element set which is the second row of the first table.
One element set which is the first row of the first table.
A set of tr tags which have "rowClass:eq(1)" class .
A set of tr tags which have "eq(1)" class .

What is the result of NaN == NaN?

true
false
An error occurs.
None of these.

$("div").find("p").andSelf().addClass("border");
The statement adds class border to ___.

all div tags and p tags in div tags
all div tags
all p tags
all p tags enclosed in div tags

$('#a1').one('click', {times: 3}, function1);
each() is a generic ___ function.

comparator
operator
iterator
normal

The hide() function hides an element by ___.

setting "display" inline style attribute of that element to "none".
setting "visibility" inline style attribute of that element to "hidden".
setting the horizontal attribute of that element to "-100".
setting the vertical attribute of that element to "-100".

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?

$(element).is(":visible")
$(this).css("visibility") == "hidden"
$(element).is(":invisible")
$(this).css("visibile") == "hidden"

Which of the following is the correct use of ajaxStart() function?

ajaxStart() function is used to start ajax call.
ajaxStart() function is used to run some code when ajax call start.
a & b
None of the above.

Which of the following is the correct use of ajaxStart() function?

The ajaxStart() function is used to start Ajax calls.
The ajaxStart() function is used to run some code when an Ajax call starts.
The ajaxStart() function is used to start Ajax calls and to run some code when an Ajax call starts.
None of these.

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?

'fast'
slow
1000ms
3000

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

add
children
filter
remove

Which of the following is the correct way to refresh a page with jQuery?

location.reload()
$(“html”).refresh()
$(“html”).load()
$(“html”).reload()

Which of the following makes use of jQuery to select multiple elements?

$('table td').eq([0, 5, 9])
$('table td:eq(0), table td:eq(5), table td:eq(9)')
$('table td').eqAny([1, 5, 9]);
None of these.

Which of the following is the correct way to distinguish left and right mouse click event in jQuery?

event.what
event.which
event.click
event.whichclick

Which of the following is correct with regards to how to upload a file asynchronously with jQuery?

In HTML5 file can be uploaded using Ajax and jQuery. Not only that, file validations(name,size,MIME-type) and handling the progress event can also be done with the HTML5 progress tag(or a div).

$('#one-specific-file').ajaxfileupload({
  'action': '/upload.php'
});

Ajax file uploads cannot be done.

$(document).ready(function() {
$("#uploadbutton").jsupload({
    action: "addFile.do",
    onComplete: function(response){
      alert( "server response: " + response);
    }   
});

What the right way to access the contents of an iframe using jQuery?

If the <iframe> is from the same domain, the elements are easily accessible as
$("#iFrame").contents().find("#someDiv").removeClass("hidden");
$('#frametest').HTML()
$('some selector', frames['nameOfMyIframe'].document).innerHTML()
All of Above

Which of the following will make the background of a page change, upon being refreshed?

$(document).ready(function() {
var totalCount = 2;
Var num = Math.ceil( Math.random() * totalCount );
Document.body.background = ‘assets/background- ‘+num+’.jpg’;
});

.$(document).ready(function() {
var num = Math.ceil( Math.random() * totalCount );
document.body.background = 'assets/background-'+num+'.jpg';
});;

$(document).ready(function() {
var totalCount = 2;
Var num = Math( Math.random() * totalCount );
Document.body.background = ‘assets/background- ‘+num+’.jpg’;
});

$(document).ready(function() {
var totalCount = 2;
Var num = Math( Math.ceil() * totalCount );
Document.body.background = ‘assets/background- ‘+num+’.jpg’;
});

Which of the following jQuery method gets a set of elements containing the unique next siblings of each of the given set of elements?

locateNext( selector )
getNext( selector)
next( selector )
None of the above.

Which jQuery method can be used to attach a function to be executed whenever AJAX request completed successfully?

ajaxStart( callback )
ajaxSuccess( callback )
ajaxSend( callback )
ajaxStop(callback)

 Which of the following is the correct way to check the existence of an element in jQuery other than the following code?

if ($(selector).length>0) {
// Do something
}

jQuery.fn.exists = function(){return this.length>0;}
if ($(selector).exists()) {
// Do something
}
jQuery.fn = function(){return this.length>0;}
if ($(selector).exists()) {
// Do something
}
jQuery.exists = function(selector) {return ($(selector).length &gt; 0);}
if ($.exists(selector)) { }

jQuery.fn.exists = function(selector) {
return selector ? this.find(selector).length : this.length;
};

Which of the following is the correct way to move an element into another element?

$('#source').prependTo('#destination');
$("#source").add("#destination");
$("#source").html("#destination");
$("#source").add().html().("#destination");

Which of the following jQuery method checks if event.preventDefault() was ever called on this event object?

isDefaultPrevented
isPropagationStopped
isImmediatePropagationStopped
None of the above

Which of the following is the correct way to assign a selected value of a drop-down list using jQuery?

$(«#myDDL»).val(2);
$(«.myDDL»).children(«option»).val(2);
$(«.myDDL»).val(‘2’);
$(«.myDDL»).children(«option»).innerText(‘2’);

Which of the following is the correct way to get HTML encoded value for any tag which function can be used?

function htmlEncode(value){
return $(‘<div/>’).text(value).html();
}
function htmlEncode(value){
return $(‘<div>>’).html();
}
function htmlEncode(value){
return $(‘<div/>’).text(value).val();
}
function htmlEncode(value){
return $(‘<div/>’).innerHTML();
}

How can an additional row be added to a table as the last row using jQuery?

$(‘#myTable tr:last’).after(‘<tr>…</tr><tr>…</tr>’);
add_new_row(‘#myTable’,'<tr><td>my new row</td></tr>’);
$(‘#myTable > tbody:last’).append(‘<tr>…</tr><tr>…</tr>’);
$(‘#myTable tr:end’).after(‘<tr>…</tr><tr>…</tr>’);

Which of the following jQuery method can be used to make an ajax call?

ready(url, [data], [callback] )
load( url, [data], [callback] )
reload(url, [data], [callback] )
None of the above.

Which of the following method is used to create custom animations in jQuery?

Css()
animate()
animation()
start_animation()

What selector would you use to query for all elements with an ID that ends with a particular string, for example ‘txtTitle’ ?

$("[id$='txtTitle']")
$("[id='%txtTitle']")
$("[id='$txtTitle']")
None of the mentioned

Which of the following jQuery method gets the children of each element in the set of matched elements?

 children(selector)
getChildren(selector)
getChild(selector)
None of the above

What does the method .one() do?

Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
Attach an event handler for all elements which match the current selector, now and in the future.
Attach an event handler function for one or more events to the selected elements.
Attach a handler to an event for the elements

Which jQuery method reduces the set of matched elements to the one at the specified index?

eq(index)
filter(index)
filterOne(index)
eqOne(index)

What does the method jQuery.getScript() do?

Load a JavaScript file from the server using a GET HTTP request.
Load a JavaScript file from the server using a GET HTTP request, then execute it.
Load data from the server using a HTTP GET request.
Load data from the server and place the returned HTML into the matched element.

Which of the following is not an ajax function settings?

datatype
error
xml
password

What does the :parent selector do?

Selects all elements that have no siblings with the same element name.
Selects all elements that have at least one child node (either an element or text).
Selects all elements that are the only child of their parent.
Selects all elements that are the nth-child of their parent.

Which of the following is correct to remove id attribute from all H2 elements with in the "content" class?

$(".content h2").removeAttr("id");
$("#content h2").removeAttrib("id");
$(".content.h2").removeAttr("id");
$(".content h2").removeAttrib("id");

Which following jQuery method adds the specified class if it is not present or remove the specified class if it is present?

toggleClass(class)
toggleClassName(class)
changeClass(class)
changeClassName(class

 Which of the following is the correct way to select <a> on the basis of href using jQuery?

jQuery(«a»).href()
jQuery(«a»).attr(«href»)
jQuery(«a[href=’url’]»)
jQuery(«a attr[href=’url’]»)

Which jQuery function can be used to filter out elements from a set of matched elements?

filter(selector)
applyFilter(selector)
setFilter(selector)
None of the above

How basic authorization can be used with jQuery ajax request?`

$.ajax({
   ...
    headers: {
        'Authorization':'Basic xxxxxxxxxxxxx',
    },
   ...
  });

$.ajax({
   ...
    headers: {
        'Basic' :  'xxxxxxxxxxxxx',
    },
   ...
  });

$.ajax({
   ...
    headers: {
        'Basic-authorization':' xxxxxxxxxxxxx',
    },
   ...
  });

$.ajax({
   ...
    defineHeaders: {
        'Authorization':'xxxxxxxxxxxxx',
    },
   ...
  });

Which of the following is correct to remove first  element in an article?

$("article a:first").empty();
$("article a:first").remove();
$("article a:first-child").remove();
$("article a first").remove();

Which of the following should be placed in the code below to alert data passed to event handler?
function myHandler( event ) {
// code .. select from the options below
$( "#box"),on( "click", { foo: "bar" } , myHandler );

alert( event.data.foo);
alert( event.foo);
alert( event.property.foo);
alert( event.object.foo);

To create your own jQuery Plugin which of the following is correct?

$.fn.your_function_name = function () {
   // code here
};

$.plugin.your_function_name = function () {
   // code here
};

$.your_function_name = function () {
   // code here
};

$.xf.your_function_name = function () {
   // code here
};

Which of the following jQuery method gets a set of elements containing the closest parent element that matches the specified selector, the starting element included?

getNearest( selector )
closest(selector)
getClosest( [selector])
None of the above.

What is the correct way of using a jQuery plugin?

Include the plugin file in the <head> of the document.
Make sure that the plugin file appears after the main jQuery source file.
Make sure that the plugin file appears before our custom JavaScript code.
All of the above

Which one of the following is not a jQuery function to get Ajax data?

load()
$.get()
$.post()
$.getJSON()
getAjax()

Let's say you show a div with an id of alert and a button as a child of that div. How would you make the div disappear after clicking the button?
Note: There may be more than one right answer.

$(‘#alert’).show(function(){
    $(‘#alert button').click(function() {
        $(this).fadeOut();
    });
});

$(‘#alert’).show(function() {
    $(‘#alert button').click($.proxy(function() {
        $(this).fadeOut();
    }, this));
});

$(‘#alert’).show(function() {
    $(‘#alert button').click(function() {
        $(‘#alert’).fadeOut();
    });
});

Which of the following is correct for selectors in jQuery?

A B  Matches all elements with tag name A that are descendants of B
A>B   Matches all elements with tag name A that are direct children of B
A-B  Matches all elements with tag name A that are immediately preceded by sibling B
A+B   Matches all elements with tag name A preceded by any sibling B

A B  Matches all elements with tag name A that are descendants of B
A>B   Matches all elements with tag name A that are direct children of B
A+B  Matches all elements with tag name A that are immediately preceded by sibling B
A-B   Matches all elements with tag name A preceded by any sibling B

A B  Matches all elements with tag name A that are descendants of B
A+B   Matches all elements with tag name A that are direct children of B
A>B  Matches all elements with tag name A that are immediately preceded by sibling B
A-B   Matches all elements with tag name A preceded by any sibling B

How would you successfully fetch some JSON data?
Note: There may be more than one right answer.

$.getJSON(‘data.json', function(results) {
    // do something
});

$.ajax({
    type: ‘get’,
    url : ‘data.json',
    data : someData,
    dataType : 'json',
    success : function(results) {
        // do something
    })
});

$.ajax({
    type: ‘get’,
    url : ‘data.json',
    data : someData,
    dataType : ‘script’,
    success : function(results) {
        // do something
    })
});

Which of the following is correct to clone the tag in an and insert them after the tag inside tag?

$("article a").insertAfter($("aside h2")).clone();
$("article a").clone().insertAfter("aside h2");
$("article a").clone().insertAfter($("aside h2"));

Which of the following filters can be used in selector?
Note: There may be more than one right answer.

:first-child
:first-of-type
:nth-child(even|odd)
:only-child

:first-child
:first-of-type
:nth-child(even|odd)
:only-of-type

:first-child
:first-of-type
:nth-last-child(n)
:last-of-type

Which of the following jQuery method binds a handler to one or more events (like click) for an element?

load(type, [data], fn )
bind( type, [data], fn )
attach(type, [data], fn )
None of the above.

Which of the following methods are no longer available in jQuery?
Note: There may be more than one right answer.

bind()
live()
load()
serialize()
size()

Which of the following jQuery method finds all sibling elements?

siblings(selector)
getSiblings(selector)
obtainSiblings(selector)
listSiblings(selector)

Which of the following is correct to create default options for plugin, provided we pass 'options' to function?

var options = $.extend({
            text         : 'Hello, World!',
            color        : red,
        }, settings);

var settings = $.default({
            text         : 'Hello, World!',
            color        : red,
        }, options);

var settings = $.extend({
            text         : 'Hello, World!',
            color        : red,
        }, options);

jQuery Test Upwork 2019