www.webdeveloper.com
Results 1 to 4 of 4

Thread: Get child id

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    678

    Get child id

    Hi,

    I have this code:

    HTML Code:
    <div id="Subscribe1" class="widget Subscribe">
    <div style="white-space: nowrap;">
    <h2 class="title">Subscribe To</h2>
    </div> 
    </div>
    I want to get the content of <h2> tag based on Subscribe1.So end result will be "Subscribe To"

    Or other way round,

    Is there any way if the id is Subscribe1 then remove <div style="white-space: nowrap;">

    Please suggest

    Thanks,

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    1. The reference of the textNode inside that <h2></h> element is
    Code:
    var txt=document.getElementById('Subscribe1').getElementsByTagName('h2')[0].firstChild.nodeValue;
    2. to remove that div when? When the user does what?

  3. #3
    Join Date
    Feb 2006
    Location
    india
    Posts
    678
    Hi Kor,

    Excellent

    You have saved my life.

    Just a question:

    If there is second h2 tag then should it be like
    HTML Code:
    var txt=document.getElementById('Subscribe1').getElementsByTagName('h2')[1].firstChild.nodeValue;
    ?

    What does this firstChild indicate?

    Please ignore about removing the child.

    Thanks once again

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    1. getElementsBytagname() returns a collection (very much alike an array), thus, yes, the second <h2> elements will have the index [1]

    2. textNodes are child nodes as well. Thus firstChild (or could be also childNodes[0]) is what its name says: the first child of the element h2, which is the textNode (the string) written there.

    See DOM (Document Object Model):
    http://www.howtocreate.co.uk/tutoria...omintroduction

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles