[thelist] Styling JavaScript created paragraph

Christian Heilmann codepo8 at gmail.com
Sun Oct 22 14:12:16 CDT 2006

> I am using Jeremy Keith's photo gallery script from his DOM Scripting book.
> Part of the script creates a paragraph within which is inserted the large
> image of the photo gallery. The paragraph is assigned the id attribute with
> description as the attribute value (id="description"). In my CSS stylesheet,
> I created a rule using text-align: center but it didn't center the large
> photo (which is narrow enough to be centered). I tried modifying the
> setAttribute method (the one that assigns the description id) by changing it
> to setAttribute("style","text-align: center;") and even
> setAttribute("align","center") but nothing worked.
> Maybe I screwed up something else in the process but if someone could tell
> me whether JS created paragraphs can be styled, that would get me started in
> the right direction.

There is no difference between Paragraphs and generated Paragraphs.
Both the set Attribute lines are invalid. If you want to do that in JS
you need to set
However, only MSIE6 centers images with the text flow. If you want to
do it in other browsers, use margin:0 auto; and display:block to
center an image.

Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/

More information about the thelist mailing list