Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Select elements where align = "center"

Tags:

jquery

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.

like image 465
AlxVallejo Avatar asked Aug 25 '26 18:08

AlxVallejo


2 Answers

Try like below,

jQuery('p.MsoNormal[align=center]').addClass('av-tablecell');
like image 73
Selvakumar Arumugam Avatar answered Aug 27 '26 19:08

Selvakumar Arumugam


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');
like image 39
Erik Avatar answered Aug 27 '26 20:08

Erik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!