Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Me1000

macrumors 68000
Original poster
Jul 15, 2006
1,794
4
My javascript skills are amateur at best, but this is what im trying to do.

I have code similar to this,
Code:
<a href="link.php" class="tempLinkForBadBrowsers"><div>lalala</div></a>
<a href="link2.php" class="tempLinkForBadBrowsers"><div>lalala2</div></a>

I would like to use javascript in order to change the links to:
Code:
href="#"
for all links that have the class tempLinkForBadBrowsers

and maybe add an "onclick" event to it, however at the moment that is being take care of with a div and isn't that important.

After about an hour of googles' failed results i figured I would just ask real people! :)


Thanks,
 
Here's a basic JavaScript function you can call to reset the href attribute all links with the same class name and also a spot for adding an event. Not sure what you were going to do with the event, so just made it do an alert.
PHP:
function RehrefLinks()
{
  var links = document.getElementsByTagName('a');
  for (var a=0, b=links.length; a < b; a++) {
    if (links[a].className == "tempLinkForBadBrowsers") {
      links[a].href = "#";
      links[a].onclick = function() { alert('clicked'); };
    }
  }
}
 
Here's a basic JavaScript function you can call to reset the href attribute all links with the same class name and also a spot for adding an event. Not sure what you were going to do with the event, so just made it do an alert.
PHP:
function RehrefLinks()
{
  var links = document.getElementsByTagName('a');
  for (var a=0, b=links.length; a < b; a++) {
    if (links[a].className == "tempLinkForBadBrowsers") {
      links[a].href = "#";
      links[a].onclick = function() { alert('clicked'); };
    }
  }
}

Thanks a million!

That is exactly what I was looking for. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.