473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

code to get a parent spans id attribute

Hi,
I am trying to pass a value of a <span> tag's id attribute to a
function. The following code is a stripped down version of what im
trying to do:

<span id="6">Name: <input name="name" type="text"><span
onClick="dosomething(???);" style="cursor:hand;">Do It!</span></span>

Where there is a <span> tag with an event handler, onClick, i want to
replace the ??? with something that will get the value of the parent
span tag, which in the above case would be '6'. i dont want to simply
enter 'dosomething(6)' as the innerHTML of the <span> tag will swap
between other <span> tags with different attribute values. if the code
could also be relative if possible too. any help would be great
because im almost finished my script. cheers

burnsy
Jul 23 '05 #1
2 1894
On 4 Apr 2004 14:33:36 -0700, mr_burns <bi******@yahoo.co.uk> wrote:
I am trying to pass a value of a <span> tag's id attribute to a
function. The following code is a stripped down version of what im
trying to do:

<span id="6">Name: <input name="name" type="text"><span
onClick="dosomething(???);" style="cursor:hand;">Do It!</span></span>


[snip]

<span ... onclick="dosomething(this.id)">

A quick question, though: what are you going to use the id value for? If
it's simply to get a reference to the element with document.getElementById
or document.all, save yourself the trouble and pass the element reference
itself:

<span ... onclick="dosomething(this)">

Good luck,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
bi******@yahoo.co.uk (mr_burns) writes:
I am trying to pass a value of a <span> tag's id attribute to a
function. The following code is a stripped down version of what im
trying to do:

<span id="6">Name: <input name="name" type="text"><span
onClick="dosomething(???);" style="cursor:hand;">Do It!</span></span>
First of all, "6" is not a valid value for the id attribute. HTML
ID's must start with a letter or underscore. I assume you are using
IE (since you use the IE specific "cursor:hand" and not the valid CSS
"cursor:pointer"). Don't expect other browsers to be as lenient wrt.
incorrect HTML.

(I assume the next to last </span> should be </a>)
Where there is a <span> tag with an event handler, onClick, i want to
replace the ??? with something that will get the value of the parent
span tag, which in the above case would be '6'.


You can use the W3C DOM to find the parent span tag:
onclick="dosomething(this.parentNode.id);"

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
2
by: Steve | last post by:
Hi, I have a nested class declaration such as: class A: def __init__(self): self.var = "A's variable" # end def class B:
11
by: Max M | last post by:
I am writing a "find-free-time" function for a calendar. There are a lot of time spans with start end times, some overlapping, some not. To find the free time spans, I first need to convert the...
2
by: Nutshell | last post by:
Hi, I would like to add an attribute to the child node if it is the only child node. The problem is I am not getting the correct count of child nodes with this template: <?xml version="1.0"?>...
4
by: Robert Dickow | last post by:
This code works perfectly in IExplorer, but in exactly the same context does not work at all in Netscape 7.x. <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> <!-- if...
4
by: darrel | last post by:
Is there a way in XSLT to write this XSL:Value-of select statement (which I've written in plain english): value of the attribute of the first ascendent to have a value. In otherwords, I have...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
6
by: Eric_Dexter | last post by:
I am writing out zero byte files with this (using python 2.5). I have no idea why I am having that problem, I am also looking for an example of readlines where I can choose a number of lines say...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.