Remove specific inline style with jquery

Evan picture Evan · Sep 29, 2010 · Viewed 21.4k times · Source

There's an asp menu I'm using that is auto inserting style="width:3px;" into my menu table tds creating a nasty gab in between my tabs. I'm testing to remove this inline style with jquery instead of our developer customizing the menu just for this cosmetic blemish.

below is a simple example:

<table border="1" cellspacing="0" cellpadding="0">
   <tr>
      <td style="width:3px;">hello world</td>
   </tr>
</table>

in jquery, i can remove all tds with the style attribute by doing:

$('td').removeAttr('style');

so, my question is, how can i target the inline style that only contains 3px?

Here's my live demo: http://jsfiddle.net/n9upF/

Answer

Brian Kim picture Brian Kim · Sep 29, 2010

You are asking how you can select td's that have style attribute with only width:3px; in it, right?

You can use Attribute Equals Selector.

$("td[style='width:3px;']").removeAttr("style");​