3

I'm trying to select only paragraphs where align="center" (inline styling).

jQuery(p.MsoNormal).attr('align', 'center').addClass('av-tablecell');

This seems to select all paragraph elements, even without align=center.

AlxVallejo
  • 3,066
  • 6
  • 50
  • 74
  • Possible duplicate of: http://stackoverflow.com/questions/1220834/jquery-how-to-select-all-elements-that-have-a-specific-css-property-applied and http://stackoverflow.com/questions/43926/jquery-can-you-select-by-css-rule-not-class – SomeKittens May 08 '12 at 15:31
  • 1
    @SomeKittens except that `align` is just an attribute, not a CSS property. – Matt Ball May 08 '12 at 15:32
  • Whoops, a bit hasty on my part. Sorry! – SomeKittens May 08 '12 at 15:33

2 Answers2

6

Try like below,

jQuery('p.MsoNormal[align=center]').addClass('av-tablecell');
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
1

Your code is setting the "align" attribute on p.MsoNormal to "center". You need to include it in your selection to get only the elements that already have "align=center" like so:

jQuery('p.MsoNormal[align="center"]').addClass('av-tablecell');
Erik
  • 935
  • 11
  • 28