Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    176
    Thanks
    14
    Thanked 1 Time in 1 Post

    Resolved (How to target DOM node)

    ~ Resolved ~

    Hi,
    I am trying to target specific DOM nodes in order to change the background color.

    The html code is:
    PHP Code:
    <div id="rightcol"><h1>Highlights Regional</h1>

    <
    div class="art"><a name="clergy"></a><h2><a href="clergy.html">Understanding AddictionRecovery Tools for Clergy and Other Congregational Leaders</a></h2>
    <
    p>A unique opportunity for clergy and congregational leaders.</p></div
    I am using this javascript phrase:

    PHP Code:
    var x=document.getElementById('rightcol').getElementsByTagName("A"); 
    It is returning all of the links within 'rightcol'. What I need is the anchors, which I wish to address by individual name.

    Thanks,

    Andy
    Last edited by 1andyw; 08-23-2007 at 08:59 PM. Reason: Resolved

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The result of document.getElementById() isn't an object that you can run getElementsByTagName() on, so that's why that doesn't work.

    If you are naming your <a> tags, why not just access them via getElementsByName()?

  • Users who have thanked Fumigator for this post:

    1andyw (08-23-2007)

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    176
    Thanks
    14
    Thanked 1 Time in 1 Post
    Resolved...

    Hi Fumigator,

    Your correct, the method of getElementsByName('clergy') works.

    Dom inspector tells me that the nextSibling of 'clergy' is the heading H2. This is the element I am trying to style.

    The code
    PHP Code:
    function getInfo(){
        var 
    el "clergy";
        var 
    elname document.getElementsByName(el);
        var 
    elsib elname.nextSibling.style.backgroundColor="yellow";    

    returns the error:

    Code:
    Error: elname.nextSibling has no properties
    Will you straighten me out on this?

    Andy
    Last edited by 1andyw; 08-23-2007 at 08:58 PM. Reason: Resolved

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    IE an Moz count in different ways the childNodes (and the next/previous Sibling as well):
    see also:
    http://www.codingforums.com/showthre...ghlight=gaps#3
    http://www.codingforums.com/showthre...ghlight=gaps#3
    Last edited by Kor; 08-23-2007 at 09:27 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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