Can I read the contents of the css class executable in code?

I have a page with a .css file associated with it. Let's say it has this content:

.wrapper {
 color:red;
}

Is there a way to read the runtime value of a .wrapper element in code?

the problem is that the runtime is linked to a different stylesheet, so wwpper is always available, but the content is always different.

what I want to accomplish is to get a value (in this case: color: red;) from the currently attached stylesheet.

Is it possible?

EDIT: is this possible on the client side, then I can somehow put it in a hidden field

+5
source share
5 answers

, ( ) CSS, .

-, , XMLHTTPRequest, .

, reg-ex , .

\.wrapper[\s|\S]*color\s*:\s*([^;]*);

    var inputfileReader = new StreamReader("path to my css file");
    string inputLine = inputfileReader.ReadToEnd() ;
    inputfileReader.Close();

    Regex cssParser = new Regex(@"\.wrapper[\s|\S]*color\s*:\s*([^;]*);");

    string myCssClass = string.Empty; ;
    if (cssParser.Match(inputLine).Groups[1] != null)
        myCssClass = cssParser.Match(inputLine).Groups[1].Value;
+3
<script type="text/javascript">
     window.getComputedStyle = window.getComputedStyle || function (element) { return element.currentStyle; };

     window.onload = function () {
          var dummy = document.createElement("span");
          dummy.className = "wrapper";
          document.getElementsByTagName("body")[0].appendChild(dummy);
          document.getElementById("<%= WrapperColorHiddenField.ClientID %>").value = getComputedStyle(dummy).color;
          document.getElementsByTagName("body")[0].removeChild(dummy);
     }
</script>

, : IE red , Chrome rgb(255,0,0)

0

[/p >

client side ,
css DOM jquery.

var testElement = $("<div></div>");
testElement.addClass("wrapper");
testElement.css("display", "none");
$("body").append(testElement);
alert(testElement.css('color'));

server side, css,
http://www.codeproject.com/KB/recipes/CSSParser.aspx

, NJ

0

CSS- . . . jquery:

$("#<%=ServerSideId.ClientID%>").addClass( className );

, .

0

All Articles