get element by id help

Discussion in 'JavaScript' started by alyskiss, Oct 5, 2011.

  1. #1
    Hi, I was wondering if anyone could help me with my javascript problem
    On a website I have breadcrumbs, for example: home>electronics>netbooks

    I need to be able to only pull the second name- electronics -
    This is what i have so far:


    <div id="breadcrumbs">
    <a href="#1">Home</a> &gt;
    <a href="#2">Laptops</a> &gt;
    <a href="#3">Netbooks</a>
    </div>


    <script type="text/javascript">


    var mylist=document.getElementById("breadcrumbs")
    var i;
    for (i=1; i<mylist.childNodes.length; i++)
    {
    alert(mylist.childNodes);
    }

    </script>

    But this alerts me with the name of the link, then an object and repeats.
    Does anyone know how to get the link out and just have the alert read "Home" "Electronics" "Netbook"
    More specifically, just Electronics...
    Thanks!
     
    alyskiss, Oct 5, 2011 IP
    Raj Kumar likes this.
  2. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #2
    use mylist.childNodes.innerHTML this will give you "Home" "Electronics" "Netbook".

    innerHTML gives text written in any html tag.


    Sheetal
     
    SheetalCreation, Oct 5, 2011 IP
  3. alyskiss

    alyskiss Peon

    Messages:
    3
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks! that worked
     
    alyskiss, Oct 6, 2011 IP