#1
  1. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0

    Grabbing Class Selector Attributes Through JavaScript


    Alrighty, how pointless. If I set up a style using a class selector:
    Code:
    .whatever { width: 200px }
    I can't get to the width property of anything that uses that class in IE?? A full example:
    Code:
    <head>
    <script language="JavaScript">
    function alertWidth(alertWhat)
    {
      alert(document.getElementById(alertWhat).style.width);
    }
    </script>
    <style type="text/css" rel="stylesheet">
    .widthThingy { width: 200px; }
    </style>
    </head>
    <body>
    <span class="widthThingy" id="foo">
    <a href="javascript:alertWidth('foo');">Clicky</a>
    </span>
    <span style="width: 200px" id="bar">
    <a href="javascript:alertWidth('bar');">Clicky2</a>
    </span>
    </body>
    The Clicky link will alert nothing. The Clicky2 link will alert '200px'. How can I get at the width attribute for boxes that use the widthThingy class? I'm only using IE5.5 and IE6.0 atm.

    Thanks,
    Chris
  2. #2
  3. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0
    Ne'er mind. In typical JavaScript fashion there's an overly complicated, typically convoluted way to do it:

    http://developer.apple.com/internet/...pt/styles.html

IMN logo majestic logo threadwatch logo seochat tools logo