Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript Question 1 (1 point) Which HTML element does NOT have a default actio

ID: 3913021 • Letter: J

Question

JavaScript

Question 1 (1 point)

Which HTML element does NOT have a default action associated with the click event?

Question 1 options:

<input>

<button>

<img>

<a>

Save

Question 2 (1 point)

Which of the following is NOT true about the event object that is created when an event occurs?

Question 2 options:

To cancel the default action of an event, you first need to create an event handler.

The event object contains information about the event that occurred.

The event object provides methods that let you control the behavior of the event.

The event object is always passed to function that handles the event.

Save

Question 3 (1 point)

You need to provide cross-browser compatible code to cancel the default action of an event

Question 3 options:

so the event can be handled with a single event handler

to ensure that all browsers store the event object in the global window.event property

because older IE browsers weren't completely DOM-compliant

to ensure that all browsers use the preventDefault() method

Save

Question 4 (1 point)

Code example 7-1
1. var eventHandler = function(evt) {
2.     if (!evt) { evt = window.event; }
3.     if (evt.preventDefault) {
4.         evt.preventDefault();
5.     }
6.     else {
7.         evt.returnValue = false;
8.     }
9. };

(Refer to code example 7-1) This is cross-browser compatible code that cancels the default action for an event. What do lines 3 - 5 do?

Question 4 options:

They cancel the default action of the event for all modern browsers.

They check to see if an event has been triggered.

They cancel the default action of the event for older versions of IE.

They check to see if the page is DOM-compliant.

Save

Question 5 (1 point)

Code example 7-1
1. var eventHandler = function(evt) {
2.     if (!evt) { evt = window.event; }
3.     if (evt.preventDefault) {
4.         evt.preventDefault();
5.     }
6.     else {
7.         evt.returnValue = false;
8.     }
9. };

(Refer to code example 7-1) Which line gets the event object for older versions of IE?

Question 5 options:

line 2

line 3

line 4

line 7

Save

Question 6 (1 point)

Why might you want to preload images on a page that uses rollovers?

Question 6 options:

To prevent delays displaying the images when the swapped images are large.

To prevent delays displaying the images when the connection is slow.

To prevent delays when the page is being loaded.

All of the above.

A and B only.

Save

Question 7 (1 point)

Assuming that the href attributes of each <a> element contains the URL for an image, what does the code that follows do?
var flowers = document.getElementsByTagName("a");
var i, flower, image;
for ( i = 0; i < flowers.length; i++ ) {
     flower = flowers[i];
     image = new Image();
     image.src = flower.href;

}

Question 7 options:

It puts the contents of all <a> elements into an array named flowers.

It creates a new Image object for each image in the flowers array.

It preloads each Image object.

All of the above.

A and B only.

Save

Question 8 (1 point)

The img elements for the thumbnails in the code that follows are coded within the <a> elements
<main>
    <h1>Image Swap</h1>
    <p>Click on an image to enlarge.</p>
    <ul id="image_list">
        <li><a href="images/pic1.jpg" title="dogs">
            <img src="thumbnails/t1.jpg" alt=""></a></li>
        <li><a href="images/pic2.jpg" title="cats">
            <img src="thumbnails/t2.jpg" alt=""></a></li>
    </ul>
    <h2 id="caption">Animals</h2>
    <p><img id="main_image" src="images/pic1.jpg" alt=""></p>

</main>

Question 8 options:

so the user can swap the main image by pressing Enter when a thumbnail has the focus

so the user can access the thumbnail links by pressing the Tab key

so the application is easy to use by the motor-impaired

all of the above

Save

Question 9 (1 point)

Code Example 7-2
JavaScript code for an Image Swap
1. var $ = function(id) {
2.     return document.getElementById(id);
3. };
4. window.onload = function() {
5.      var listNode = $("image_list");
6.      var captionNode = $("caption");
7.      var imageNode = $("main_image");
8.      var imageLinks = listNode.getElementsByTagName("a");
9.      var i, image, linkNode, link;
10.     for ( i = 0; i < imageLinks.length; i++ ) {
11.         linkNode = imageLinks[i];
12.         image = new Image();
13.         image.src = linkNode.getAttribute("href");
14.         linkNode.onclick = function(evt) {
15.             link = this;
16.             imageNode.src = link.getAttribute("href");
17.             captionNode.firstChild.nodeValue = link.getAttribute("title");
18.             if (!evt) { evt = window.event; }
19.             if (evt.preventDefault) { evt.preventDefault(); }
20.             else { evt.returnFalse = false; }
21.         };
22.     }
23.     imageLinks[0].focus();
24. };

(Refer to Code Example 7-2) Which lines of code attach an event handler for the click event of each link?

Question 9 options:

line 8

lines 11 - 13

lines 14 - 17

line 14 - 21

Save

<input>

<button>

<img>

<a>

Explanation / Answer

1) <img> does not have a default click event.

A click event basically means, something should happen we click an element. When we click on <input> it enables a user to input. <button> is also an element which executes some code when it is clicked on. <a> is a hyperlink element. It links us to a new webpage.

-------------------------------------------------------------------

2) The event object provides methods that let you control the behavior of the event.

The event object does not provide methods that can help us control the event. An Event Object only has the information about the type of event that is occuring. These Events are then passed onto Event handler which controls the behaviour.

------------------------------------------------------------

3) to ensure that all browsers use the preventDefault() method

The older version of Internet Explorers did not recognize this method properly . Hence it was necessary to provide a cross compatible code.

-----------------------------------------------------------

4) They cancel the default action of the event for all modern browsers.

preventDefault() method is used to cancel the default action of the event. At times we would want a element to do its default action. For eg:- When a user is submitting a form we would not want submit button to do its actual work. Why? Let's see what a submit button does, it taked in the data and processes it. But Just assume what if the user has not actually filled the entire form, it would be a problem then.

So, we will prevent the default action of submit button.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote