문제

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?

도움이 되었습니까?

해결책

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()); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top