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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to access min and max CSS properties from JS

    It would appear that it is not possible to retrieve CSS properties such as min-width if they have been set from a class. However, I don't want to have to style everything directly with the style attribute whenever I need these properties. Is there a reliable method of getting these properties as applied to element from a CSS class?
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #2
    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
    someElement.style refers to CSS properties that have been set in its style attribute. So it's not just max-width, but any property.

    In standards-compliant browsers such as Safari, Opera, and Firefox:
    Code:
    document.defaultView.getComputedStyle(someElement, "").getPropertyValue("max-width")
    Will obtain the computed value for max-width.

    Similarly in IE:
    Code:
    someElement.currentStyle.maxWidth
    (even though IE<7 doesn't support the max-width property)

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    In standards-compliant browsers such as Safari, Opera, and Firefox:
    Code:
    document.defaultView.getComputedStyle(someElement, "").getPropertyValue("max-width")
    Cool, that's what I was after. I knew about currentStyle but I didn't know about getComputedStyle.

    Thanks jkd!
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."


  •  

    Posting Permissions

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