jQuery Quiz


Given the current version of jQuery, jQuery 1.4.2, the following example code, and the list of browsers below, determine which elements are matched by jQuery in each problem. The code appears in a valid HTML document, with the following CSS applied, and no other scripts.

Many of the question answers use the language "element from line n". This is to be interpreted as: "The element created from parsing line n."

You are encouraged to use the jQuery API documentation as well as w3c documents Selectors Level 3, CSS 2.1, and any other online documentation.

At the bottom of the test are links to the example documents that show the actual outcome of running the code in both quirks and in standards mode.

Example Code


img, input {
    padding: 1px;
* {
    width : 600px;
    padding: 0;
    margin: 0;

Why Include CSS for a Selectors Quiz Example?

Selectors Level 3 selects nodes based in the DOM (regardless of CSS).

JQuery.com claims that jQuery is CSS3 compliant, and so if that is true, then the CSS can be disregarded as irrelevant.


1.   <img width="600" src="logo.gif" id="imageOne" style="display: none" alt="Write less">
2.   <img src="logo.gif" id="imageTwo" alt="Do More!">
3.   <img width="100" src="logo.gif" id="imageThree"  alt="Write less">
4.   <img width="0" src="logo.gif" id="imageFour"  alt="Write less">
5.   <input type="image" width="600" src="logo.gif" id="inputOne" alt="Write less">
6.   <input type="image" width="100" src="logo.gif" id="inputTwo" alt="Do More!">
7.   <input type="image" src="logo.gif" id="inputThree" alt="Write less">
8.   <input type="image" src="logo.gif" width="0" id="inputFour" alt="Write less">
9.   <pre>-</pre>



Example Problem (hide/show)

Select the single most correct answer. Any answer that applies to at least one browser in the list above is true.

What does document.execCommand("SaveAs", false, "test.html") do?

Answer: d. all of the above.

In Internet Explorer, a "Save As" dialog box will be presented to the user. In Firefox 3.6, nothing will happen, making "b" correct. Other browsers will throw a TypeError, making "c" correct. Thus, the single most correct answer would be: d. "all of the above".

Test Problems

  1. $("*[width]") matches:
  2. $("img[width]") matches:
  3. $("*[width=600]") matches:
  4. $("img[width=600]") matches:
  5. $("img[width='600']") matches:
  6. $("*[width=0]") matches:
  7. $("html > body input").length results
  8. $("html > * input").length results
  9. $("> * input", "html").length results
  10. $("html > * input[width='600']").length results

Example Page