Gregor Gregor - 4 months ago 9
Javascript Question

Why is this .each function working wrong

i have this function to print the image size of all having the

attribute [proto]
.

When i try it with this
each
method, its only giving back a function.

Where is my mistake? Please help.

function size(){
var $img = $('img[proto]');
$($img).each(function(){
var height = $(this).height;
var width = $(this).width;
$(this).parent().find('p').remove();
$(this).parent().append('<p class="size">' + width + '-' + height + '</p>');

});
}
size();

Answer

These are functions not properties, height and width:

var height = $(this).height();
var width = $(this).width();
Comments