dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: How to change text align with Javascript

  1. #1
    Join Date
    Oct 2005
    Posts
    7

    How to change text align with Javascript

    Hello~

    I know that " this.style.backgroundColor" could change background color.

    But what should I do to change text align with Javascript?

    I try to use: this.style.textalign="center";

    But it doesn't work.


    Thanks.

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    JavaScript is case-sensitive.
    Code:
    this.style.textAlign
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  3. #3
    Join Date
    Oct 2005
    Posts
    7
    Thanks a lot!
    And could you tell me where I could find these resources?
    Thank U

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Rule 1:

    compounded CSS attributes loose the hyphen and the second(third...) word use Upper case first letter

    backgroundColor
    textAlign

    Rule 2:

    compounded HTML attributes use for second(third...) word Upper case first letter

    colSpan
    bgColor
    readOnly

  5. #5
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    And remember the exception to the rule: HTML "class" becomes Javascript "className".
    Stephen

  6. #6
    Join Date
    Oct 2005
    Posts
    7
    Thank you very much

  7. #7
    Join Date
    May 2008
    Posts
    4
    divId1.style.textAlign = "left",
    The above line works only in IE, it does'nt work in other browsers.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    text is align anyway left by default, so I don't understand how could you have noticed that error I bet you try to align a picture (which is treated as an inline element by IE). Show us the full code, please

  9. #9
    Join Date
    May 2008
    Posts
    4
    Ya just now i tried to align the text to right, center, left in a separate page.
    It works fine even in ff, I think there is some more settings that i have to change in my big junk of code.
    Thanks a lot.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles