views:

6273

answers:

3

I need to vary a table's width after a click event in jQuery.

HTML:

<table class="zebra" border=0>

Case 1:

    $("table.zebra").css("width","600px");

Case 2:

   $("table.zebra").css("width","200px");

CSS:

 table.zebra{}
 table.zebra tr.even td, table.zebra tr.even th { background-color:#FDD017; } 
 table.zebra tr.odd td { background-color:#FFF380; }

This does not change the table's width like I want.

What am I doing wrong?

+1  A: 

Try this:

$("table.zebra").width(200);

Reference: http://docs.jquery.com/CSS/width#val

Koistya Navin
still I not able to get Resize the Table width?
venkatachalam
the width() will get the current computed width of the first matched element, according to http://is.gd/9VR3. Not a setter, I think.
Sepehr Lajevardi
@Sepehr, there is a setter as well .width(val)
Koistya Navin
thanks Koistya, sorry for the bump!
Sepehr Lajevardi
A: 

This should do the trick.

<table class="zebra">
  <tr>
    <td>foo</td>
    <td>bar</td>
  </tr>
</table>

<script type="text/javascript">
  $(function() {
    $('table.zebra').attr('width', 500);
  });
</script>
William Brendel
A: 

This should do the trick

$("table.zebra").width('200px');
Paul Hachmang