Felix K.

asked • 09/20/22

Hi I need help with the question below

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) What would happen if lines 18 through 20 were omitted?


  A) Clicking on a link would cause the caption, but not the larger image, associated with the link to be displayed.

 

  B) The code would only work in older versions of IE.

 

  C) Nothing would happen when the user clicks on one of the links.

 

  D) Clicking on a link would open a new browser window or tab and display the image specified by the href attribute of the link.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.