I’ve included code in my project I don’t understand.
// where dImage is an existing image entity on my page
$("<img>").attr("src", $(dImage).attr("src")).load(function() {
1) what does $("<img>") mean? I would assume it means all image entities in the DOM, but when i tried to $("<img>").attr("woah","baby"); and then inspect the dom, there’s no trace of my custom attribute. why?
2) why is this value undefined in load callback? $("<img>").attr("src"); = undefined.
3) what would this code be expected to do?
Insight greatly appreciated. What is the use of this statement?
1) No.
$('<img>')creates a new image element, which will get thesrcobtained from thedImageelement. For “all image entities in the DOM”, you’d do$('img'), just like a CSS selector.2) Which value?
$("<img>").attr("src"); = undefined.is invalid code. If you actually mean thesrcof$("<img>"), then again it’s because$("<img>")creates a newimgelement.3) Create a new image, assign the
src, and attach aloadevent handler that is invoked when the image is finished loading.