SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A question about style

    Hello,

    Some code like
    Code:
    document.getElementById('tr'+x).style
    would not retrive the style of a 'tr' in an html page.

    So what's the trick?
    -1/2=999?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As far as I know it does, but only the explicitly set style.

    Code html4strict:
    <div style="font-weight:bold"><div id="a">aaa</div></div>
     
    <script type="text/javascript">
     var s=document.getElementById('a').style;
     document.write(s.fontWeight); //outputs nothing
    </script>
    Code html4strict:
    <div id="a" style="font-weight:bold">aaa</div>
     
    <script type="text/javascript">
     var s=document.getElementById('a').style;
     document.write(s.fontWeight); //outputs 'bold'
    </script>
    Saul

  3. #3
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change style without reloading the page!

    Thanks, helped out.

    I actualy want it for this task. onclick of a link which is in "bold font style" changes it to normal font style or style="". I think what we did covers this part but I want to whenever I get back to that page without reloading it the style be in the normal format.

    Hope I could say my words in a simple way. Please let me know if not.
    Last edited by borna; Jun 12, 2007 at 02:44.
    -1/2=999?

  4. #4
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the best and simplest [to some extent] way to DHTML. I think reload without refresh is kind of dhtml.

    Please let me know of some link and rich refrences.
    -1/2=999?

  5. #5
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can always check if the style property is empty, then you know it must be bold:

    Code javascript:
    var a = document.getElementById('foo');
    toggleBold (a);
     
    function toggleBold (elm)
    {
      if (!elm.style.fontWeight ||
           elm.style.fontWeight == '' ||
           elm.style.fontWeight == 'bold')
      {
        // fontWeight is not set or font-weight is bold, toggle it:
        elm.style.fontWeight = 'normal';
      }
      else elm.style.fontWeight = 'bold';
    }

    It's not the most flexible of functions, but it should do the trick in your case.


Bookmarks

Posting Permissions

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