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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -