문제

I have a table with three columns. I am using tag to specify the width of a column. Sample code:

<table width="100%" border="1">
  <colgroup style="background-color:#FF0000;">
  <col width="100px" id="id1"></col>
  <col width="80px" id="id2"></col><col id="id3"></col></colgroup>
  <tbody>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
  <tr>
    <td>2489604</td>
    <td>My first CSS</td>
    <td>$47</td>
  </tr>
<tbody>
</table>

The problem is width of col ($("#id1").width()) returns 0 for IE and Chrome and it works fine in FF. How do I get the actual width of col in chrome and IE?

도움이 되었습니까?

해결책

Do the simple hack for older jQuery (col don't have width in Chrome, but it have first cell with width )

<table width="100%" border="1">
  <colgroup style="background-color:#FF0000;">
  <col width="100px"></col>
  <col width="80px"></col><col id="id3"></col></colgroup>
  <tbody>
  <tr>
    <th id="id1">ISBN</th>
    <th id="id2">Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
  <tr>
    <td>2489604</td>
    <td>My first CSS</td>
    <td>$47</td>
  </tr>
<tbody>
</table>

here - http://jsfiddle.net/YD5mM/2/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top