SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Difference between Class and Name properties in HTML, as applied to JavaScript

    Okay, so I understnad how the class attribute works in CSS: I can specify that every attribute with class="foo" be italicized with:
    .foo {font-style: italic;}

    What if I want to do the same sort of thing in Javascript? Is there something built-in like
    document.GetElementsbyClass("foo").style = "italic" (I'm just making this code up of the top of my head, I don't know how javascript works.)

    It seems to me that with JavaScript you're supposed to use the name="" attribute instead of class="". Why the diference?

    I looked at webmonkey that had an article about this, but their writing style is simply confusing and I can't make heads or tails of their articles.

    Any suggestions appreciated.

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript uses the ID tag to do what you are looking for. This is how it works.

    document.getElementById('foo').style.fontStyle="italic";

    Notice how the wording is different as well these are your text options

    fontSize
    fontStyle
    lineHeight
    verticalAlign
    textDecoration
    etc...

    as for an article - http://www.webreference.com/js/column73/index.html

    it covers using tag names and such to work with for animation which relates directly to changing the elements styles
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


Bookmarks

Posting Permissions

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