SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2005
    Location
    New York, NY, U.S.
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get...attribute?

    I'm trying to get the text inside of a link element. So lets say i had
    Code:
    <a href="blah">Text</a>
    and I want to get the Text in that. How would I do so. can I use getAttribute somehow? or is there a different way to do it? Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,015
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    attribute

    In <a href="blah">Text</a>, href is the attribute, so you can use getAttribute to get "blah". If you want to get "Text", try innerHTML or childNode/textNode

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2005
    Location
    New York, NY, U.S.
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just remembered about childnodes, so on
    Code:
    <a href="blah">Text</a>
    I used childNodes[0].nodeValue and that gives me Text (of course I could also use firstChild.nodeValue). Hope someone else can benefit from this thread, sorry for the wasted thread. Thanks for the reply Mittineague.


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
  •