Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Style vs. currentStyle

    Hey,

    I am getting more and more into actually reading about CSS and javascript rather than just using code from tutorials that I don't necessarily understand. I have figured out a lot of stuff, but I have become stumped over the difference between currentStyle and Style. I have read up on currentStyle over at MSDN (http://msdn.microsoft.com/library/de...rrentstyle.asp ) but I am still confused.

    I guess I am trying to figure out if I specify CSS in the head section of my page, i.e.:

    Code:
    <head>
    <style type="text/css">
    <!--
    .content {font-color: #990033;}
    -->
    </style>
    </head>
    What is currentStyle going to return compared to what just flat out style will return?
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it says it on that page:

    The currentStyle object returns the cascaded styles on an element, but the style object returns only the styles that have been applied inline on an element through the style attribute

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey brothercake,

    I know it says that there, but I guess my real problem is that I am not sure what that means. I think it says that if I don't directly specify the style on a certain tag but that tag is being styled because it is inside a different tag that is specified a style then Style will return nothing, but currentStyle will return the style that is being cascaded onto my no-styled tag (hmm, I hope that made sense ). But I am not sure if that is correct...
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it means that if you go

    <div style="color:green"></div>

    you can retrieve the color property with obj.style.color

    But if you had defined that color using a class name and a stylesheet, you would use currentStyle to retrieve it.

    I believe there's also a property "getComputedStyle" which returns the overall result (ergo computed style) of an element's styling from external CSS and inline. Not too sure about that though .. maybe someone else can fill in here ...
    Last edited by brothercake; 12-28-2002 at 01:48 AM.

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    document.defaultView.getComputedStyle(element, '').getPropertyValue('prop-name')

    defaultView is defined in DOM2 Views, and extended by DOM2 CSS to include getComputedStyle.

    Only Mozilla supports this much of the DOM2 specs. (Opera 7 might actually... I don't remember off hand).

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So - does that clear it up for you, or do you still have questions?

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that did the trick, sorry it took me so long to reply though ! Anyway, I think I get the whole currentStyle and style deal, but that whole getComputedStyle bit is a little much for me at this point. That's okay though because I don't feel a strong need to understand that right now!!

    Thanks!
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •