SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

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

    returning data from href or li

    assuming your href or li has an id tag, is there a way to return their values?

  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)
    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)
    right, I am trying to use DOM, I just don't know the property for the anchor?

    It's not value, it's not innerHTML ??

  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)
    Quote Originally Posted by Golgotha View Post
    right, I am trying to use DOM, I just don't know the property for the anchor?

    It's not value, it's not innerHTML ??
    You seem not to understand it though. In the DOM what you want to access is the nodeValue of the text node which is a child of the <a> element node. It's not directly a property of the element at all.

    Don't use innerHTML. It's not standard and it can cause many headaches.

    When you use the following, the "this" keyword doesn't point to the element. It points to the global object, which is known as "window". It's bad practice to use the javascript: pseudo-protocol anyway.
    Code:
    href='javascript:getThisFeed(this)'
    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.

  5. #5
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my example: this returns undefined.

    Code:
    <script type="text/javascript">
       function getThisFeed(thisFeed)
       {
        alert(thisFeed.innerHTML);
       }
    </script>
    
    <a href='javascript:getThisFeed(this)' id='feed1'>some text here...</a>

  6. #6
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      
    <script type="text/javascript">
    
       function getThisFeed(thisFeed)
       {
    alert(thisFeed.innerHTML); // some text here...
       
    alert(thisFeed.firstChild.data); // some text here...
    
    alert(thisFeed.firstChild.nodeValue) ;  // some text here...
    
    alert(thisFeed.childNodes[0].nodeValue) ;  // some text here...
    
    alert(thisFeed.childNodes[0].data) ;  // some text here...
    
    alert(document.getElementById('feed1').firstChild.nodeValue); // some text here...
    
    alert(document.getElementById('feed1').firstChild.data); // some text here...
    
    alert(document.getElementsByTagName('a')[0].innerHTML); // some text here...
    
    alert(document.getElementsByTagName('a')[0].firstChild.nodeValue); // some text here...
    
    alert(document.getElementsByTagName('a')[0].firstChild.data); // some text here...
    
    alert(document.getElementsByName('a0')[0].innerHTML); // some text here...
    
    alert(document.getElementsByName('a0')[0].firstChild.nodeValue); // some text here...
    
    alert(document.getElementsByName('a0')[0].firstChild.data); // some text here...
    
    alert(document.getElementsByName('a0')[0].childNodes[0].data); // some text here...
    
    alert(document.getElementsByName('a0')[0].childNodes[0].nodeValue); // some text here...
    
       }
    </script>
    
    <a href='' onclick='javascript:getThisFeed(this)' id='feed1' name="a0">some text here...</a>
    Code:
      
    <script type="text/javascript">
    
       function getThisFeed(thisFeed, myId)
       {
       alert(myId); 
       alert(thisFeed.innerHTML); 
       alert(thisFeed.firstChild.nodeValue); 
       alert(document.getElementById(myId).innerHTML); 
       alert(document.getElementById(myId).firstChild.nodeValue); 
    
       }
    </script>
    <ul>
    <li id="li1" onclick="getThisFeed(this, this.id)">liste 1 </li>
    <li id="li2" onclick="getThisFeed(this, this.id)">liste 2 </li>
    <li id="li3" onclick="getThisFeed(this, this.id)">liste 3 </li>
    </ul>
    Last edited by muazzez; Feb 17, 2007 at 03:51.

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="nojs.html" onclick='getThisFeed(this);return false;' id='feed1'>some text here...</a>


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
  •