Skip to content

Instantly share code, notes, and snippets.

@mauricioschneider
Created August 18, 2014 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioschneider/ae607f56e7744466a74c to your computer and use it in GitHub Desktop.
Save mauricioschneider/ae607f56e7744466a74c to your computer and use it in GitHub Desktop.
<!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