Setting the width and heights value in div's style tag from variables

拟墨画扇 提交于 2021-02-05 06:36:05

问题


In my javascript file I have the following line:

<div id="mygraph" style="width:200px;height:100px;"></div>

I'd like to set the width and height values in the style tag from two variables that take their values from the corresponding functions:

var my_width = getWidth();
var my_height = getHeight();

How can I accomplish that? I'm missing the correct syntax. Thank you in advance...


回答1:


The following assumes that my_height and my_width returned by your functions are plain numbers:

document.getElementById('mygraph').style.height = my_height + "px";
document.getElementById('mygraph').style.width = my_width + "px";


来源:https://stackoverflow.com/questions/11040780/setting-the-width-and-heights-value-in-divs-style-tag-from-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!