Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <style>
  2.  
  3. .test {
  4.  
  5. background-color: Red;
  6. width: 500px;
  7. border-bottom: solid 1px blue;
  8. }
  9.  
  10. </style>
  11. <script>
  12.  
  13. function getStyleWidth(className) {
  14. var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
  15. var classIndex = classes.length;
  16. while (classIndex--) {
  17. if (classes[classIndex].selectorText == className) {
  18. var cssText = classes[classIndex].style.cssText;
  19. var styleStartIndex = cssText.search(/width:/i); // get start index
  20. var styleEndIndex = cssText.indexOf(";", styleStartIndex); // get end index
  21. var widthValue = cssText.substring(styleStartIndex, styleEndIndex); // remove other styles
  22. widthValue = widthValue.replace(/width:/i, "").replace(/;/, "").replace(/ /, "").replace(/px/i, ""); // strip "width:" + ";" + " " + "px"
  23. return widthValue;
  24. }
  25. }
  26.  
  27. }
  28. alert(getStyleWidth('.test'));
  29.  
  30.  
  31. </script>
Add Comment
Please, Sign In to add comment