I am trying to loop through over each div that has a class of block and set it's height individually based on it's data-attribute data-height
HTML
<div class="block" data-height="300"></div>
<div class="block" data-height="500"></div>
<div class="block" data-height="700"></div>
jQuery
$('.block').each(function(){
var size = $this.attr('data-height');
$(this).height(size);
});
JS Fiddle http://jsfiddle.net/MLnBY/166/
It's not returning the height when I have it in the each method though thus not setting the height for each one.
The problem is in $this; replace it with $(this)
var size = $(this).attr('data-height');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With