...

View Full Version : Resolved (How to target DOM node)



1andyw
08-23-2007, 03:24 PM
~ Resolved ~

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

The html code is:

<div id="rightcol"><h1>Highlights Regional</h1>

<div class="art"><a name="clergy"></a><h2><a href="clergy.html">Understanding Addiction: Recovery 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:


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

Fumigator
08-23-2007, 04:58 PM
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()?

1andyw
08-23-2007, 07:23 PM
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

function getInfo(){
var el = "clergy";
var elname = document.getElementsByName(el);
var elsib = elname.nextSibling.style.backgroundColor="yellow";
}

returns the error:


Error: elname.nextSibling has no properties

Will you straighten me out on this?

Andy

Kor
08-23-2007, 08:22 PM
IE an Moz count in different ways the childNodes (and the next/previous Sibling as well):
see also:
http://www.codingforums.com/showthread.php?t=109445&highlight=gaps#3
http://www.codingforums.com/showthread.php?t=84797&highlight=gaps#3



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum