Created
August 18, 2014 21:34
-
-
Save mauricioschneider/ae607f56e7744466a74c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Obtener estilo definido por clase.</title> | |
<style> | |
.test{ | |
font-size: 14px; | |
height: 400px; | |
background: #fff; | |
} | |
</style> | |
<script> | |
function getStyle(className) { | |
var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules; | |
for (var x = 0; x < classes.length; x++) { | |
if (classes[x].selectorText == className) { | |
(classes[x].cssText) ? alert(classes[x].cssText) : alert(classes[x].style.cssText); | |
} | |
} | |
} | |
console.log(getStyle('.test')); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment