SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Get all links.

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Get all links.

    Hi All!

    How I can get all links(as object) form <div> element.

    Sample
    <div id="my_div">
    <p>
    <a href="1.html">..</a>
    </p>
    <div id="temp">
    <a href="2.html">..</a>
    </div>
    </div>

    I need all links form "my_div". (1 and 2)

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    var links = document.getElementById("my_div").getElementsByTagName("a");
     
    for (var i = 0, n = links.length; i < n; ++i) {
        // do something with each links[i]
    }
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tnanks!


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
  •