D ... the preventDefault is there to make sure that an event does not use the default action (here following the link).
Felix K.
asked 09/20/22Hi I need help with the question below
Code Example 7-2
JavaScript code for an Image Swap
- var $ = function(id) {
- return document.getElementById(id);
- };
- window.onload = function() {
- var listNode = $("image_list");
- var captionNode = $("caption");
- var imageNode = $("main_image");
- var imageLinks = listNode.getElementsByTagName("a");
- var i, image, linkNode, link;
- for ( i = 0; i < imageLinks.length; i++ ) {
- linkNode = imageLinks[i];
- image = new Image();
- image.src = linkNode.getAttribute("href");
- linkNode.onclick = function(evt) {
- link = this;
- imageNode.src = link.getAttribute("href");
- captionNode.firstChild.nodeValue = link.getAttribute("title");
- if (!evt) { evt = window.event; }
- if (evt.preventDefault) { evt.preventDefault(); }
- else { evt.returnFalse = false; }
- };
- }
- imageLinks[0].focus();
- };
(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
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.