473,408 Members | 2,734 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,408 software developers and data experts.

How to find the ID of the "current" element

Hello. A question.
It is possible to refer to the ID of an element within the element
itself? And, if yes, what is the instruction or function.

Example. Assume I have this:

<div id="Square1" onclick = "Clicked('Square1')"></div>

You see the ID of the element "Square1" also appears later on the
function invocation "Clicked('Square1')". My question is: can I replace
the second occurrence of "Square1" with an instruction indicating the
current ID element? How?
For instance, I assume the instruction existed and were
"CurrentElmID()", I would have:

<div id="Square1" onclick = "Clicked(CurrentElmID())"></div>

Hope my question is clear. Thanks.

-Pam

Aug 23 '06 #1
4 10893
wrote on 23 aug 2006 in comp.lang.javascript:
Hello. A question.
It is possible to refer to the ID of an element within the element
itself? And, if yes, what is the instruction or function.
Example. Assume I have this:

<div id="Square1" onclick = "Clicked('Square1')"></div>
[..]

<div id = 'Square1' onclick = 'alert(this.id)'>
Content
</div>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 23 '06 #2
Evertjan. wrote:
wrote on 23 aug 2006 in comp.lang.javascript:
Hello. A question.
It is possible to refer to the ID of an element within the element
itself? And, if yes, what is the instruction or function.
Example. Assume I have this:

<div id="Square1" onclick = "Clicked('Square1')"></div>

[..]

<div id = 'Square1' onclick = 'alert(this.id)'>
Content
</div>
Although virtually the only useful thing that can be done with that ID
is to use it to look up a reference to the element in the DOM, and as -
this - is a reference to that element at the point when its - id -
property is read it would be more sensible to pass the reference on the
function called instead of a string ID.

Richard.

Aug 23 '06 #3

Thanks Evertjan, very helpful.

Thanks Richard for the comments.
I need it because I prefer to have updatable code in one place only:
more maintenable.

I hope there are no browser compatibility issues with this one :).

Thank you very much.

-Pam

Richard Cornford ha scritto:
Evertjan. wrote:
wrote on 23 aug 2006 in comp.lang.javascript:
Hello. A question.
It is possible to refer to the ID of an element within the element
itself? And, if yes, what is the instruction or function.
Example. Assume I have this:
>
<div id="Square1" onclick = "Clicked('Square1')"></div>
[..]

<div id = 'Square1' onclick = 'alert(this.id)'>
Content
</div>

Although virtually the only useful thing that can be done with that ID
is to use it to look up a reference to the element in the DOM, and as -
this - is a reference to that element at the point when its - id -
property is read it would be more sensible to pass the reference on the
function called instead of a string ID.

Richard.
Aug 23 '06 #4
Richard Cornford wrote on 23 aug 2006 in comp.lang.javascript:
Evertjan. wrote:
>wrote on 23 aug 2006 in comp.lang.javascript:
Hello. A question.
It is possible to refer to the ID of an element within the element
itself? And, if yes, what is the instruction or function.
Example. Assume I have this:

<div id="Square1" onclick = "Clicked('Square1')"></div>

[..]

<div id = 'Square1' onclick = 'alert(this.id)'>
Content
</div>

Although virtually the only useful thing that can be done with that ID
is to use it to look up a reference to the element in the DOM, and as -
this - is a reference to that element at the point when its - id -
property is read it would be more sensible to pass the reference on the
function called instead of a string ID.
"Going back to square1" should be an option.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 23 '06 #5

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

Similar topics

14
by: Don G | last post by:
Within the menu for my site, I have inserted 'class="current"' within the link for the current page. So the link looks somthing link: <li><a href="index.php" class="current">Home</a></li> The...
3
by: Matej Cepl | last post by:
I know about element.style.fontSize, but it seems to work here (with Mozilla Firefox 1.0.6) just only when the fontSize was set via CSS. Can I get somewhere current size of the font in the actual...
4
by: Davids | last post by:
darn stuck again! in my string array string myArray = string; Let's say I've put a string field into the first 3 items and I guess the other 23 must then be null, right? OK so is there any C#...
1
by: VB Programmer | last post by:
When my users login I want them to be able to change some of their personal info in a db. I want to use a detailsview control for this. How can I get the detailsview to only pull up the record...
3
by: RR | last post by:
I have a button on a form (form A) that opens another form. The form that opens (form B) has a listbox that is populated with a call to a function in the "on current" event. When form B with the...
2
by: MLH | last post by:
Suppose that code running on FormB is moving the focus around on FormA to various textbox controls on FormA - Which form is the current form during this process? Is it FormA, which has the...
8
by: Jeremy | last post by:
If we have a table with say 3 rows in it and one of the columns contains a checkbox such as <table> <tr> <td><input type="checkbox" name="ch_fld"></td> </tr> <tr> <td><input type="checkbox"...
3
by: Bob Cohen \(106531\) | last post by:
I want to define some metadata using custom attributes to apply to properties in various classes. The properties return values that are classes themselves. I want to retrieve the attribute...
13
by: Alex | last post by:
For example, i have some part of XML file. <AppSettings> <Object ClassVersion="1.0.0.0" Type="AppSettings"> <Fields> <Field Name="App_ID" Type="System.Int32"> <Value> <int>-1</int> </Value>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.