Javascript : selecting elements within a element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chathura86
    New Member
    • May 2007
    • 227

    Javascript : selecting elements within a element

    i want to select all ul tags with in a given div tag

    eg.
    Code:
    <div id="a">
        <ul>
              <li>asdad .....</li>
              <ul>
                     <li>asdad .....</li>
                     <li>asdad .....</li>
                     <li>asdad .....</li>
              </ul>
              <ul>
                     <li>asdad .....</li>
                     <li>asdad .....</li>
                     <li>asdad .....</li>
              </ul>
        </ul>
    </div>
    so i want select only the ul tags in the javascript
    cannot use id for ul tags because they are generating dynamically
    and there are other ul tags out side this div tag

    chathura bamunusinghe
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use the getElementsByTa gName method on the div:
    [code=javascript]var uls = document.getEle mentById("a").g etElementsByTag Name("ul");[/code]

    Comment

    • chathura86
      New Member
      • May 2007
      • 227

      #3
      it works
      thank you very much

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome :)

        Comment

        Working...