Add Attribute Jquery data type string + variable -


i have variable called vp_height want put data variable, putting this, prompt error.

var vp_height = viewportsize.getheight();  //sample data $(".carol").attr({     "data-" + vp_height : "width:50%;" }); 

here's error

enter image description here

it should in frontend. (visual presentation)

<div class="staff-container carol" data-667="width:50%;"></div> 

any solution stuff?

you can use:

$(".carol").attr("data-" + vp_height, "width:50%;"); 

fiddle demo


Comments

Popular posts from this blog

rest - Spring boot: Request method 'PUT' not supported -

php - Magento - Deleted Base url key -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -