I am trying to let the user set styles dynamically, but I also want to grab the values of certain styles. For example, I want to check if the user sets the color of an H1 element to 'orange'.
My HTML
<body ng-controller="mainController">
<h1 id="myH1">Hello World!</h1>
<textarea ng-model="outputCss"></textarea>
<style media="screen" type="text/css">
{{outputCss}}
</style>
</body>
My Javascript, in mainController
var myH1Style = document.getElementById('myH1').style;
$scope.$watch('outputCss', function(newValue, oldValue){
if (myH1Style.color == "orange"){
alert("Nice work!");
}
console.log(myH1Style.color);
});
Example User Input
#myH1 {
color: orange;
}
h1 {
font-weight: 900;
}
The problem is, the if condition can never be met, and the console log is always empty. How can I read CSS properties that are added using this method?