I simply need a little of help adding a text align of center to p tags when they contain a picture. I want this to have the ability to center attached images within wordpress. Appreciate every assist you to may have the ability to offer!

You should use [cde] to limit the group of all has elements to individuals that have p elements, after which use [cde] to alter the home:


Alternatively, you could utilize the [cde] selector:


However, the $("p").has("img").css({textAlign: "center"}); technique is faster compared to selector.

With jQuery:


Simply because I went this through JS Perf, I decided to publish an ordinary JS version (that, in Chromium 14/Ubuntu 11.04, may be the quickest method of fixing the issue):

$("p:has(img)").css({textAlign: "center"});

Along with a JS Fiddle.



Use has: http://api.jquery.com/has/