#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0

    <td> width using javascript


    Hi all,
    I want to access the width of the table data <td> using javascript.
    I have code
    --------------------------------------------------------------
    <table>
    <tr>
    <td id="widthA" width="20">Width of this cell is to be calculated</td>
    </tr>
    </table>
    -----------------------------------------------------------------
    I tried with document.all.widthA.clientWidth and it worked well in IE but in Netscape it is not working.
    How can I make it work in both versions???

    Any Help is greatly appreciated.

    Thanks and Regards

    Raju
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Buenos Aires, Argentina
    Posts
    74
    Rep Power
    12
    document.all only works on IE
    Try with document.getElementById("widthA")
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    Hi
    I tried with document.getElementById("WidthA")
    but itsn't working.

    Thanks and Regards
    Srinivas Raju
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Buenos Aires, Argentina
    Posts
    74
    Rep Power
    12
    This one is working

    Code:
    <HTML>
    <HEAD>
    </HEAD>
    <BODY id="relleno">
    <table> 
    <tr> 
    <td id="widthA" width="20">Width of this cell is to be calculated</td> 
    </tr> 
    </table> 
    <script>
    	alert(document.getElementById("widthA").clientWidth) //shows 62
    	alert(document.getElementById("widthA").width) // shows 20
    //	document.getElementById("widthA").clientWidth = 50; // commented because it won't work, clientWidth is read only
    	document.getElementById("widthA").width = 50;
    	alert(document.getElementById("widthA").width) // shows 50
    </script>
    </BODY>
    </HTML>
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0
    Hi Malinali,
    Thanks a lot for the replies. Well I tried with
    1. alert(document.getElementById("widthA").clientWidth)
    2. alert(document.getElementById("widthA").width)

    First one is working fine in IE but not in netscape or mozilla whereas second one is fetches the widthwhich u mentioned and if you have not mentioned it then blank.

    But I got the solution anyhow. I tried this one
    alert("offsetWidth="+document.getElementById("widthA").offsetWidth);

    Its working in both IE and mozilla.

    Thanks for the replies....


    Thanks and Regards
    Srinivas Raju

IMN logo majestic logo threadwatch logo seochat tools logo