Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / October 2005



Tip: Looking for answers? Try searching our database.

Overriding a href using onClick

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
VA - 31 Oct 2005 04:49 GMT
Firefox 1.0.7

If I launch Jesse Ruderman's Javascript shell

http://www.squarefree.com/2005/10/30/javascript-shell-14/

on any web page and type in the shell

var mylink
for (j=0;j<document.links.length;j++) {
mylink=document.links[j];
if (mylink.href.match(/something/)) {
  mylink.href="#";
  mylink.onClick="alert('clicked');return false;";
}
}

I expected all my links having "something" in them to now popup my
alert box.

But nothing happened, no errors in the Javascript console, nothing
happens when I click on those links.

What gives?

Thanks
Lee - 31 Oct 2005 05:18 GMT
VA said:

>Firefox 1.0.7
>
[quoted text clipped - 18 lines]
>But nothing happened, no errors in the Javascript console, nothing
>happens when I click on those links.

Links don't have an onClick attribute.
They do have an onclick attribute, but it should be assigned a
reference to a function, not a string value.
VA - 31 Oct 2005 05:39 GMT
> Links don't have an onClick attribute.
> They do have an onclick attribute, but it should be assigned a
> reference to a function, not a string value.

So how would I modify my snippet above to do what I want it to do?

Thanks
Randy Webb - 31 Oct 2005 06:52 GMT
VA said the following on 10/30/2005 11:39 PM:

>>Links don't have an onClick attribute.
>>They do have an onclick attribute, but it should be assigned a
>>reference to a function, not a string value.
>
> So how would I modify my snippet above to do what I want it to do?

You change onClick in your code to onclick

CaSe MaTtErS

Signature

Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

Mick White - 31 Oct 2005 17:48 GMT
>>Links don't have an onClick attribute.
>>They do have an onclick attribute, but it should be assigned a
>>reference to a function, not a string value.
>
> So how would I modify my snippet above to do what I want it to do?

mylink.onclick=function(){alert('clicked');return false;}

Mick
Andrew Poulos - 31 Oct 2005 06:59 GMT
> var mylink
> for (j=0;j<document.links.length;j++) {
[quoted text clipped - 4 lines]
>  }
> }

You could try:

var mylink
for (var j = 0; j<document.links.length; j++) {
 mylink = document.links[j];
 if (mylink.href.match(/something/)) {
   mylink.href = "#";
   mylink.onclick = function() {
     alert("clicked");
     return false;
   }
 }
}

Andrew Poulos
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.