Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript DOM Problem-Urgent

Status
Not open for further replies.

caffeinerusher

Programmer
Mar 7, 2001
31
US
Hi,

I have a link on a page with a declared class and a declared ID. There is a rollover on this link that calls a javascript function. The ID of the link is passed to the function. Using this value, I need to access the className of that link. For instance.. theID is the value of the ID passed from the link. linkID is the actual value of the ID.

function test(theID) {
alert(linkID.className);
alert(theID);
}

If I call this function on a mouseover, it gives me the className of the link and gives me the value of the ID (linkID). The problem is that I do not want to have to hardcode the name of ID in the function I need it to take the ID value and plug it in. theID.classname does not work. Please Help

--Caffeinerusher
 
Hi there.

For DOM, I think something like the following should do the trick:

Code:
function test( id ) {
    var node = document.getElementById( id );
    var className = node.getAttribute( 'className' );
    alert( className );
}

Personally, I thought the atribute you would want is 'class' instead of 'className'. Hope this helps.

Cheers, NEIL s-)

 
or you might want to do this:

<script language=&quot;JavaScript&quot;>
<!--
function test(theID) {
eval('alert(' + theID + '.className);');
alert(theID);
}
// -->
</script>

<a href=&quot;#&quot; onMouseOver=&quot;test('duck');&quot; id=&quot;duck&quot; class=&quot;bird&quot;>mouse over me</a>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top