SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript / DOM help

    rssFeeds is a UL with list items. Each list item holds a link.

    it's returning #, not the actually anchor text?

    How do I return the anchor text?

    Code:
        function addToDBFeed()
        {
            var objFeeds = document.getElementById("rssFeeds");
            
            var colFeedAnchors = objFeeds.getElementsByTagName("a");
            var strFeedAnchors = "";
            
            for (var i = 0; i<colFeedAnchors.length; i++)
            {
                strFeedAnchors += colFeedAnchors[i];
            }
            
            alert(strFeedAnchors);
            
        }

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    colFeedAnchors[i] is a reference to an <a> element. You seem to want its href property.
    Code:
    strFeedAnchors += colFeedAnchors[i].href;
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want the href - I want the anchor text.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this then (this assumes the <a>'s first child is a text node and not another element.)
    Code:
    strFeedAnchors += colFeedAnchors[i].firstChild.nodeValue;
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •