0

Using jquery can td width be overwritten as shown

<table>
<tr>
<td width="30%"></td>
<td width="70%" id="description"></td>
</tr>
</table>

<script>
 $("#description").css({"width":"30%"})
</script>
1
  • Your HTML is not valid (missing <tr>) and you don't have an id set on the table cell for the jQuery code to work. Commented Dec 9, 2010 at 11:14

2 Answers 2

1

Put all your jQUery code inside document ready event.

$(function(){
     $("#description").removeAttr("width").css({"width":"30%"});
});

width should be set inside style and not as an attribute. First remove the attribute and then set the style. If you can use a class then it will be the best approach.

.elwidth
{
    width: 30%;
}

 $(function(){
         $("#description").removeAttr("width").addClass("elwidth");
 });
Sign up to request clarification or add additional context in comments.

Comments

0

Short answer: yes.

<table>
  <tr>
    <td id="firstCell" width="30%">...</td>
    <td id="secondCell" width="70%">...</td>
  </tr>
</table>

<script>
  $("#firstCell").attr("width", "40%");
  $("#secondCell").attr("width", "60%");
</script>

Although you shouldn't be using width attributes, rather use CSS properties to set the widths of table cells.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.