473,386 Members | 1,720 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,386 software developers and data experts.

Change onClick for an anchor tag

I'm using:

document.getElementById("mylink").childNodes[0].nodeValue = "New
Text";

To change the text value of a link that I've created.

How can I do something similar to change the onclick event?

(doesn't work)
document.getElementById("mylink").onClick="alert(' test')";

Thanks,
Cliff.

Jul 23 '05 #1
3 14070
delray...@gmail.com wrote:
I'm using:

document.getElementById("mylink").childNodes[0].nodeValue = "New
Text";

To change the text value of a link that I've created.

How can I do something similar to change the onclick event?

(doesn't work)
document.getElementById("mylink").onClick="alert(' test')";

Thanks,
Cliff.


It's 'onclick' (lower-case) for one thing.

You need to assign either a actual function (object) or a pointer:

document.getElementById("mylin*k").onclick=functio n(){alert('test');};

You could, naturally, just use document.createElement('a') to make a
new Link, set its attributes, and call .replaceChild().

Jul 23 '05 #2
You will need to assign a function object to onclick event handler:
document.getElementById("mylink").onclick = function() {
alert("onclick"); } works fine but onclick can send implicit Event
object to the handler which can be quite useful. So you can also set
onclick like: document.getElementById("mylink").onclick =
function(event) { alert(event.type); }

Jul 23 '05 #3
pr********@gmail.com wrote on 28 apr 2005 in comp.lang.javascript:
You will need to assign a function object to onclick event handler:


Please quote!!!!!!!

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

Jul 23 '05 #4

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

Similar topics

2
by: Christian Kusenbach | last post by:
Hello group! I've a problem with JavaScript and IMG-Objects. On my webpage I use a big image and several small images. If you click on a small image, it executes a JavaScript to change the...
1
by: Will | last post by:
(My 4 questins at end after explination) The code below was provided to me to "Popup" a window explaining what a Credit Card Verification Number is and where to find it on a card... it is used as...
2
by: deko | last post by:
I'm trying to change the font style of a link when that link is clicked. But the link (sometimes) includes a named anchor. So I need to test for a given named anchor and apply style changes if...
4
by: Jerry Sievers | last post by:
JS Programmers, "I'm a server-side coder PHP, Postgres etc... My question; Given the following anchor <a href="http://www.somesite.com/somefile.html">link text</a> Is there a way to code an...
6
by: eswanson | last post by:
In jscript, I would like to be able to set the href attribute of the anchor element. I have a aspnet:hyperlink button on the page, but I would like to be able to set the href attribute of this...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
5
by: Simon Benson | last post by:
Probably a fairly simple problem but one that's been plaguing me for a couple of days... can anyone help? I have a classic ASP page with a number of text boxes which are updatable. For...
1
by: pbd22 | last post by:
Hi. I am trying to add an "onclick" 'event to an anchor tag and this is proving harder than I imagined. The anchor HAS NO ID. And, there will be tons of them on the page. So, I cannot access...
11
by: nma | last post by:
Hi How can I make the anchor link once I do onclick? <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor="#00ff00" onMouseOver="this.style.background ='red'" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.