javascript - Set DIV height for each by it's data-attribute -
i trying loop through on each div has class of block , 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 height when have in each method though not setting height each one.
the problem in $this
; replace $(this)
var size = $(this).attr('data-height');
Comments
Post a Comment