Which code segment should you use?

You create a Web page that contains the following image element.
<img id=”myImage” src=”/image1.png” />
You need to write a JavaScript function that will dynamically change which image is displayed. The
function must be compatible across different browsers. Which code segment should you use?

You create a Web page that contains the following image element.
<img id=”myImage” src=”/image1.png” />
You need to write a JavaScript function that will dynamically change which image is displayed. The
function must be compatible across different browsers. Which code segment should you use?

A.
function changeImage() {
myImage.src = “image2.png”;
}

B.
function changeImage() {
document.getElementById(“myImage”).src =
“image2.png”;
}

C.
function changeImage() {
getElementById(“myImage”).src =
“image2.png”;
}

D.
function changeImage() {
window.getElementById(“myImage”).src =
“image2.png”;
}



Leave a Reply 0

Your email address will not be published. Required fields are marked *