473,473 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to get the currently linking element?

is it possible to get the currently linking element?

for example, I wire up an onclick event for some anchor tags, is it
possible in this onclick event, I can know which anchor tag is being
clicked?

"this" does not work

thanks!

Jun 12 '06 #1
6 1338
so*********@gmail.com said the following on 6/12/2006 11:15 AM:
is it possible to get the currently linking element?
Yes.
for example, I wire up an onclick event for some anchor tags, is it
possible in this onclick event, I can know which anchor tag is being
clicked?
onclick="alert(this)"
"this" does not work


Yes it does. Or post a sample that doesn't do what you think it should.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 12 '06 #2

thanks for reply.

what I am doing is

// a is a link object
AddEventHandler(a, "click", specialExecution);

function specialExecution()
{
// if I alert(this); it shows [object]

// but if I do the following
var url = this.href;

// it is undefined
alert(url);
}

Jun 12 '06 #3
BTW, the above code works in FireFox, but not in IE
so*********@gmail.com wrote:
thanks for reply.

what I am doing is

// a is a link object
AddEventHandler(a, "click", specialExecution);

function specialExecution()
{
// if I alert(this); it shows [object]

// but if I do the following
var url = this.href;

// it is undefined
alert(url);
}


Jun 12 '06 #4
how about:
function addEvent(obj, type, fn){
if (obj.attachEvent){
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn](window.event);}
obj.attachEvent('on'+type, obj[type+fn]);
}else
obj.addEventListener(type, fn, false);
}

var a = document.getElementById("myaID");
addEvent(a, "click", function(){alert(this.href)});

<so*********@gmail.com> schreef in bericht
news:11**********************@h76g2000cwa.googlegr oups.com...
BTW, the above code works in FireFox, but not in IE
so*********@gmail.com wrote:
thanks for reply.

what I am doing is

// a is a link object
AddEventHandler(a, "click", specialExecution);

function specialExecution()
{
// if I alert(this); it shows [object]

// but if I do the following
var url = this.href;

// it is undefined
alert(url);
}

Jun 12 '06 #5
so*********@gmail.com said the following on 6/12/2006 11:28 AM:
thanks for reply.
Thanks for quoting what you are replying to next time.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
what I am doing is

// a is a link object
AddEventHandler(a, "click", specialExecution);

function specialExecution()
{
// if I alert(this); it shows [object]
That is because 'this' refers to the the current function which is an
[object], you don't need a reference to the function, you want a
reference to the link and the link will have to give the 'this' reference.
// but if I do the following
var url = this.href;

// it is undefined
That is because the function doesn't have an href property although you
could give it one. And since it doesn't exist, it is undefined.
alert(url);
}


Is AddEventHandler from Prototype.js?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 13 '06 #6
Randy Webb <Hi************@aol.com> writes:
// a is a link object
AddEventHandler(a, "click", specialExecution);
function specialExecution()
{
// if I alert(this); it shows [object]


That is because 'this' refers to the the current function which is an
[object], you don't need a reference to the function, you want a
reference to the link and the link will have to give the 'this'
reference.


No, in this case (invocation of an event handler attached using
attachEvent) "this" refers to the global object.

Had it been attached using addEventHandler, the "this" operator would
have provided the object that the handler had been added to.

/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.'
Jun 13 '06 #7

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

Similar topics

1
by: Ben | last post by:
Hi all, I'm relatively new to C++ and have a quick question concerning a better way to perform runtime linking. Currently a client wishes to create a class in a .dll. I export 2 methods from my...
0
by: Dibyendu Roy | last post by:
Hi All, I build an object called "dblorcle" to connect to oracle database in Sun solaris box. This is built linking with various oracle ".a" (archived, for static linking) files come with standard...
4
by: George Hester | last post by:
I have a form that has 4 <INPUT> elements in it each with a unique id. The page loads with the <INPUT> id = 1 with focus. If a tab is done immediately without entering anything in this INPUT text...
3
by: Headless | last post by:
Should linking generated content work? Example: span:before{content:"foobar"} <a href="foobar.htm"><span></span></a> I stumbled across this bit in the CSS2 spec: >Generated content does...
3
by: soup_or_power | last post by:
Hi Sorry about the heading. I have a table with td consisting of lists with <select></select>. When I do a document.getElementById("element").innerHTML I don't see the selected item. IOW, the...
1
by: Jan Limpens | last post by:
Hi, given a schmea and the currently selected element (via XPath) of a XmlDocument that uses this schema, I want to allow a xml editor to give the user a choice of possible ChildNode Elements....
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
0
by: Martin Landa | last post by:
Hi, I am writing Python extension in C++, in this extension I am using methods from another Python extension. On Linux I am currently linking my extension with used Python extension -- what is...
4
by: aaragon | last post by:
Hi everyone, I have a linking error when using gcc4.2 and static member variables. The class template definition is something around the following: template<> class Element<L2_t: public...
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
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,...
1
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.