jQuery Quiz Questions 11-20

Share this article

Following on from jQuery Quiz Questions 1-10 here are questions 11-20. Hopefully you might learn something new about jQuery you didn’t know before. Once more if you find any mistakes please feel free to leave a comment with corrections. Enjoy!

Question 11

Which of the following is the correct way to check which key was pressed using jQuery? Answers
  • $('#txtValue').keypress(function (event) {
        $('#txtvalue').alert((event.keyCode));
    });
    
  • $(‘#txtValue’).keypress(function (event) {
        alert(String.fromCharCode((event.keyCode)));
    });
    
  • $(‘#txtValue’).keypress(function (event) {
        alert(fromCharCode((event.keyCode)));
    });
    
  • $(‘#txtValue’).keypress(function (event) {
        $(‘#txtvalue’).alert((event.which));
    });
    
Correct Answer
$(‘#txtValue’).keypress(function (event) {
    $(‘#txtvalue’).alert((event.which));
});
API: http://api.jquery.com/keypress/  

Question 12

Consider the following code snippet:
$('#ul1 li').on('click', function1);
$('#ul1').after('
  • Last item
  • ‘); Is function1 executed if “lastLi” is clicked? Answers
    • yes
    • no
    Correct Answer no. The .after() function adds the list item outside the UL tag.  

    Question 13

    $("ul#myId > li");
    What does the above statement return? Answers
    • A set of tags whose id is “li”.
    • A set of tags which contains class “li”.
    • A set of li tags which are children of ul tags that have “myId” class.
    • A set of li tags which are children of ul tags that have “myId” id.
    Correct Answer A set of li tags which are children of ul tags that have “myId” id.  

    Question 14

    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 ___. Answers
    • the rows of table1 at order 3n + 1 (n = 0, 1, 2, …) have class firstRowClass
    • the rows of table1 at order 3n (n = 1, 2, …) have class firstRowClass
    • all rows of table1 have class firstRowClass
    • no rows of table1 have class firstRowClass
    Correct Answer the rows of table1 at order 3n + 1 (n = 0, 1, 2, …) have class firstRowClass see answer in action: https://jsfiddle.net/jquery4u/zJW3B/  

    Question 15

    Which of the following is the correct way to move an element into another element? Answers
    • $('#source').prependTo('#destination');
    • $("#source").add("#destination");
    • $("#source").html("#destination");
    • $("#source").add().html().("#destination");
    Correct Answer
    $("#source").add("#destination");
     

    Question 16

    Consider the following code snippet:
    $('span.item').each(function (index) {
        $(this).wrap('
  • Item
  • '); });
    Essentially, what does this code snippet do? Answers
    • Wraps each span tag that has class item within a li tag.
    • Inserts each span tag that has class item into a li tag.
    • Inserts Item into each span that has item class.
    • Replaces each span tag that has class item with a
    • Item
    • .
    Correct Answer Wraps each span tag that has class item within a li tag. see answer in action: https://jsfiddle.net/jquery4u/gv2vq/  

    Question 17

    What is the result of the following code snippet?
    jQuery.unique([1, 2, 2, 3, 3, 1]);
    
    Answers
    • [1, 2, 3].
    • [3, 2, 1].
    • [1, 1, 2, 2, 3, 3].
    • None of the above.
    Correct Answer [1, 2, 3]. see answer in action: https://jsfiddle.net/jquery4u/gkJsP/
     

    Question 18

    Consider the following code snippet:
    $('#table1').find('tr').hide().slice(10, 20).show();
    
    What is the result of this code snippet? Answers
    • Showing table1’s rows from 11th to 20th.
    • Showing table1’s 20 rows from 10th.
    • Deleting rows of table1 from 10th to 20th.
    • Deleting 20 rows of table1 from 10th onward.
    Correct Answer Showing table1’s rows from 11th to 20th. see answer in action: https://jsfiddle.net/jquery4u/MQjer/  

    Question 19

    $("div").find("p").andSelf().addClass("border");
    
    The statement adds class border to ___. Answers
    • all p tags enclosed in div tag
    • all div tags and p tags in div tags
    • all div tags
    • all p tags
    Correct Answer all div tags and p tags in div tags see answer in action: https://jsfiddle.net/jquery4u/eUBup/  

    Question 20

    Which of the following statements return(s) a set of p tags that contain “jQuery”? Answers
    1. $('p:contains(jQuery)');
    2. $('p:contains("jQuery")');
    3. $('p:has("jQuery")');
    4. 1 and 2
    5. 1 and 3
    Correct Answer 1 and 2 see answer in action: https://jsfiddle.net/jquery4u/cAnHC/  

    Frequently Asked Questions (FAQs) about jQuery Quiz

    What is the purpose of the jQuery quiz?

    The jQuery quiz is designed to test your knowledge and understanding of jQuery, a fast, small, and feature-rich JavaScript library. It covers various aspects of jQuery, including syntax, effects, events, and more. The quiz is a great way to assess your skills and identify areas where you may need to improve. It’s also a fun and interactive way to learn and reinforce what you’ve learned about jQuery.

    How can I prepare for the jQuery quiz?

    To prepare for the jQuery quiz, you should first have a basic understanding of HTML, CSS, and JavaScript, as jQuery is built on these technologies. You can then study jQuery through various resources, such as online tutorials, books, and practice exercises. Practicing coding with jQuery and building small projects can also help you understand and remember the concepts better.

    What topics does the jQuery quiz cover?

    The jQuery quiz covers a wide range of topics, including jQuery syntax, selectors, events, effects, AJAX, and more. It tests your understanding of how to use jQuery to simplify tasks such as HTML document traversal and manipulation, event handling, and animation.

    How is the jQuery quiz structured?

    The jQuery quiz consists of multiple-choice questions. Each question presents a code snippet or a scenario, and you need to choose the correct answer from the given options. The quiz is designed to be challenging and thought-provoking, requiring you to apply your knowledge and understanding of jQuery.

    Can I retake the jQuery quiz?

    Yes, you can retake the jQuery quiz as many times as you want. The purpose of the quiz is to help you learn and improve, so feel free to take it again if you want to test your knowledge or see how much you’ve improved.

    What should I do if I don’t understand a question in the jQuery quiz?

    If you don’t understand a question in the jQuery quiz, you can try to break it down and understand the code or scenario presented. You can also refer to jQuery documentation or tutorials for help. If you’re still stuck, don’t worry. The purpose of the quiz is to learn, so it’s okay if you don’t know everything.

    How can I use the jQuery quiz to improve my skills?

    You can use the jQuery quiz to identify areas where you need to improve and focus your learning on those areas. The quiz can also help you practice applying your knowledge, which is crucial for mastering jQuery. Additionally, taking the quiz regularly can help you track your progress and see how much you’ve improved over time.

    Is the jQuery quiz suitable for beginners?

    The jQuery quiz is designed to be challenging, but it’s suitable for anyone with a basic understanding of HTML, CSS, and JavaScript. If you’re a beginner, the quiz can help you see how much you’ve learned and what you need to focus on. If you’re more experienced, the quiz can help you reinforce your knowledge and identify any gaps.

    Can I use the jQuery quiz for interview preparation?

    Yes, the jQuery quiz can be a useful tool for interview preparation. It covers many of the topics that are commonly asked in interviews for web development positions. By taking the quiz, you can get a sense of what kind of questions you might be asked and practice answering them.

    What other resources can I use to learn jQuery?

    In addition to the jQuery quiz, there are many other resources you can use to learn jQuery. These include online tutorials, books, video courses, and practice exercises. You can also learn by building projects with jQuery, which can help you understand how to apply the concepts in real-world scenarios.

    Sam DeeringSam Deering
    View Author

    Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

    jQuery
    Share this article
    Read Next
    Get the freshest news and resources for developers, designers and digital creators in your inbox each week