Otra manera:
Código PHP:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>...</title>
<style>
.div1{ background:red; color:white;}
</style>
<script type="text/javascript">
function addCss(cssCode,i) {
control=document.getElementById(i)
if(control)
document.getElementsByTagName("head")[0].removeChild(control)
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = cssCode;
} else {
styleElement.appendChild(document.createTextNode(cssCode))
}
styleElement.id =i;
document.getElementsByTagName("head")[0].appendChild(styleElement);
}
</script>
</head>
<body>
<div class="div1">Cuando despertó, el dinosaurio todavía estaba allí.</div>
<script type="text/javascript">
addCss('.div1{ width:200px; height:200px;background:black; color:red; padding:10px; cursor:pointer}.div1:hover{background:red; color:white;}','esdin1');
</script>
</body>
</html>