开发者

can a javascript get the value of the div width from a css file

开发者 https://www.devze.com 2023-01-04 23:47 出处:网络
can a javascript开发者_Python百科 get the value of the div width from a css file, if yes, then please tell me how :)CSS files TELL what to set.The DOM (Document Object Model) HAS what it is currently

can a javascript开发者_Python百科 get the value of the div width from a css file,

if yes, then please tell me how :)


CSS files TELL what to set. The DOM (Document Object Model) HAS what it is currently which is the document.

var mydiv = document.getElementById("mydiv");
var curr_width = parseInt(mydiv.style.width); // removes the "px" at the end

Makes the assumption your have a div with id="mydiv"

edit1: There are also these:

document.getElementById("mydiv").clientWidth;
document.getElementById("mydiv").offsetWidth;

Edit2: just because it will probably come up: offsetWidth will include the width of any borders, horizontal padding, vertical scrollbar width, etc.


You're probably looking for some of the methods/properties associated with the StyleSheetList object stored in the document.styleSheets property.

See:

http://www.javascriptkit.com/domref/stylesheet.shtml

0

精彩评论

暂无评论...
验证码 换一张
取 消