By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

How to know id of object

P: n/a
I have something lik this...
<td>

<a href="#" onClick="changecolor();">Change color of first TD you get</a>
</td>
Assuming that I don't know the Id of TD how can I, browsing DOM,
manipulate the first TD that I encounter bubbling up in the document?

Any help appreciated.

Best regards.

--
Gibe si è fatto passare perchè Rossi dietro è come una purga, prima o
poi una cagata te la fa fare...!
Sep 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Fabri wrote on 20 sep 2005 in comp.lang.javascript:
I have something lik this...
<td>
<a href="#" onClick="changecolor();">Change color of first TD you
get</a>
</td>

Assuming that I don't know the Id of TD how can I, browsing DOM,
manipulate the first TD that I encounter bubbling up in the document?


onClick="changecolor(this)"

and go from there with .parent ...

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 20 '05 #2

P: n/a


Fabri wrote:

<td>

<a href="#" onClick="changecolor();">Change color of first TD you
get</a>
</td>
Assuming that I don't know the Id of TD how can I, browsing DOM,
manipulate the first TD that I encounter bubbling up in the document?


If you do
<a onclick="changecolor(this);"
then
function changecolor (node) {
you have e.g. the link element node passed to the function and can use
the DOM stuff on that node e.g. access the parent node hierarchy
var parentNode = node.parentNode;
if (parentNode) {
while (parentNode && parentNode.nodeType == 1 &&
parentNode.tagName.toLowerCase() != 'td') {
parentNode = parentNode.parentNode;
}
if (parentNode && parentNode.tagName.toLowerCase() == 'td') {
// you have a <td> element here
}
}
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.