Adding styles to dynamically generated tables in Javascript. The setattribute issue in Javascript

Source: Internet
Author: User

If you use JavaScript to dynamically generate a table, there will be a lotCode.

However, there are still few materials on the online style for dynamically generated tables, but I still find them.

Source: http://www.xhtmlhelp.net/javascript/15051.html

<! -- Inject script filtered -->

ThisIsParagraph #1.

ThisIsParagraph #2.

Parent. setattribute ("style", "text-align: Center ");
Bold. setattribute ("style", "text-align: Center ");

 

These two sentences are intended to center the text, but have no effect.
I tried for half a day and didn't find the cause, but I can replace the sentence with document. getelementsbytagname ("p") [0]. setattribute ("align", "center"); can achieve the same effect
Forfor2006-9-16Although in HTML But in JS, this is the form of element. style. textalign = "center"; instead of element. Style = "text-align: center ;"

P.s. do not place block-level elements (such as P) into inline-level elements (such as B). If you want to use element. style = "text-align: center;" format, which can be written
Element.style.css text = "text-align: center ;"

Parent. style. setattribute ("csstext", "text-align: Center ");

This kind of situation does not need to be shown and used, not like direct element.style.css text = "text-align: center ;"

//////////////////////////////////////// //////////////////////////////////////

Source: http://thinkway.spaces.live.com/Blog/cns! 1pbqqn3pamqciygnqvf99isa! 150. Entry

Use of setattribute in Javascript

I spent more than half a night! The style attribute is not implemented by a simple setattribute!

//////////////////////////////////////// /////////////////////////

If you want to add a CSS style table to a table:

Document. getelementbyid ("your settings"). classname = "your class"

<! -- Inject script filtered -->

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.