Which code segment should you use?

You create a Web page that contains the following div.

<div id=”target”>
</div>

You have a JavaScript array named imageurls that contains a list of image URLs.
You need to write a JavaScript function that will insert images from the URLs into target.
Which code segment should you use?

You create a Web page that contains the following div.

<div id=”target”>
</div>

You have a JavaScript array named imageurls that contains a list of image URLs.
You need to write a JavaScript function that will insert images from the URLs into target.
Which code segment should you use?

A.
$(imageurls).each(function(i,url){
$(“<img/>”, url).append(“#target”);
});

B.
$(imageurls).each(function(i,url){
$(“#target”) += $(“<img/>”).attr(“src”, url);
});

C.
$.each(imageurls, function(i,url){
$(“<img/>”).attr(“src”, url).appendTo(“#target”);
});

D.
$.each(imageurls, function(i,url){
$(“#target”).append(“<img/>”).src = url;
});



Leave a Reply 0

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