passing id of an element as a parameter in javascript...

S

soyo

I have the following code:

<a id="check" href=# onClick="script1();"><input
type=button.......></a>
Now to this script1() function above I want to pass the "id" of the
anchor tag so that I can access the child elements in my javascript
function script1()

the way I do now is:

<a id="check" href=# onClick="script1(id);"><input
type=button.......></a>

script1(id)
{
document.getElementById(id).firstChild;
}


but it says "id" undefined.

how do I do that?
can u also show me how to access the child nodes in the javascript
code.
 
L

Lee

soyo said:
I have the following code:

<a id="check" href=# onClick="script1();"><input
type=button.......></a>
Now to this script1() function above I want to pass the "id" of the
anchor tag so that I can access the child elements in my javascript
function script1()

the way I do now is:

<a id="check" href=# onClick="script1(id);"><input
type=button.......></a>

script1(id)
{
document.getElementById(id).firstChild;
}

Don't pass the id if you're just going to immediately look up
a reference to the element. Just pass a reference to the element:

onclick="script1(this)"

function script1(ref) {
ref.firstChild

What's supposed to be the point of putting a button inside a link?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top