Pergunta

I am trying to set a block's height equal to its width with this $('.block').height($(this).width()); However it's not working properly for some reason. Please see an example: http://jsfiddle.net/Uy3YB/. What do I need to correct?

Foi útil?

Solução

Fiddle Demo

$('.block').height(function () {
    return $(this).width();
});

.height( function(index, height) )

A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, this refers to the current element in the set


Problem with your code

this below is the window object not $('.block')

$('.block').height($(this).width()); 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top