Question

I'm trying to change the width of a div to be the same as the width of a table cell. Neither will be fixed widths, so also need to be able to detect when the size changes. Trying to accomplish something like the below, but not sure how.

var myvalue = document.getElementsByClassName('tableCell'); 
document.getElementByClassName('test').style.width= myvalue.offsetWidth+'px';

<table>
  <tr>
    <td colspan="2"><div class="test"></div></td>
  </tr>
  <tr>
    <td class="tableCell">test</td>
    <td></td>
  </tr>

Was it helpful?

Solution

$(document).ready(function() {
  $('.test').width( $('.tableCell').width() );
});

http://jsfiddle.net/wpNFk/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top