Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- .test {
- background-color: Red;
- width: 500px;
- border-bottom: solid 1px blue;
- }
- </style>
- <script>
- function getStyleWidth(className) {
- var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
- var classIndex = classes.length;
- while (classIndex--) {
- if (classes[classIndex].selectorText == className) {
- var cssText = classes[classIndex].style.cssText;
- var styleStartIndex = cssText.search(/width:/i); // get start index
- var styleEndIndex = cssText.indexOf(";", styleStartIndex); // get end index
- var widthValue = cssText.substring(styleStartIndex, styleEndIndex); // remove other styles
- widthValue = widthValue.replace(/width:/i, "").replace(/;/, "").replace(/ /, "").replace(/px/i, ""); // strip "width:" + ";" + " " + "px"
- return widthValue;
- }
- }
- }
- alert(getStyleWidth('.test'));
- </script>
Add Comment
Please, Sign In to add comment