SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist artcoder's Avatar
    Join Date
    Aug 2005
    Location
    Planet Earth
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can JS read arbitary attributes in an element

    If backend script writes out the following ...

    Code:
    <ul id="mylist" mycolor="red">
    <li>one</li>
    <li>two</li>
    </ul>
    where mycolor is an "made-up" attribute.

    I want JS to read to me the value of the "mycolor" attribute -- in this case the answer is "red".

    Is there something like ...

    document.getElementById("mylist").getAttribute("mycolor").value

    that will work?

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes.
    Birnam wood is come to Dunsinane


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
  •