Attribute as a Variable

Attribute as a Variable

I'm trying do to add some data attributes to a DIV, but this attribute has to be a variable.


  1. var HEIGHT = window.innerHeight; // 740

  2. $('div').attr('data-' + HEIGHT, 'value');
So the DIV should look like:

  1. <div data-740='value'></div>
Every time I try to do this, I just don't get it to work, or I get the Variable name on the attribute.

Anyone with som advise?