That's how jQuery works, it's the expected behavior.
$()
turns DOM element(s) into a jQuery object (which pretends to be an array), which is a set of DOM element(s).
In your answer you don't need to use $()
.
Since, this
is the element you want, you can just do:
template.find('.userPhoto img').error(function () {
this.src = '/images/default.png';
}).attr('src', image);
Or you can do this:
template.find('.userPhoto img').error(function () {
$(this).attr('src', '/images/default.png';);
}).attr('src', image);
$(this).attr('src'
will change the attribute of all elements (in your case, one) in the set.