View Full Version : HELP!! Converting HTML <a> tag to JAVASCRIPT

06-21-2010, 09:11 AM
ok, quick and to the point. I have this...

<a href="www.mylink.com" class="myclass">click</a>

and I wanna change it to a javascript function that can be called via the SAME tag, but with this link:

<a href="javascript: myfunction()">click</a>

Here's what i have so far:

<script type="text/javascript">

function myfunction()

<a href="javascript: myfunction()">click</a>

this works to the point where it only opens the link, but now i can't figure out how to add the class to it. I tried adding it inside the body tag, but it doesn't work. So, I'm wondering if it's possible to set the class in the javascript.

Thanks in advance for the help, I really appreciate it :)

06-21-2010, 09:45 AM
<a href="http://www.mylink.com" class="myclass" onclick="myfunction(this.href); return false;">click</a>

<script type="text/javascript">

function myfunction(value)

btw, what's your actual goal?

06-21-2010, 07:55 PM
that almost worked! but didn't.

sorry, i forgot to mention what it's for.

I'm building a website and for all the pictures and images, I'm using a plugin called colorbox (http://colorpowered.com/colorbox/). When you click on a link with a certain class, in my case, "class=flashdirect" it opens the link in a javascript popup (not on a separate window, but a zoom popup within the same window.

Now, I'm making the website so that the only thing that loads is the content under the menu, while the menu stays the same. For that I'm using an "iFrame" for all the pages in the website. So far everything is going well. The only thing is that I'm using "colorbox" within the iframe. I have it set so when I click on a thumbnail, it opens up a youtube video in a javascript popup, but the problem is that it pops up within the iframe.


I want it that when i click on the thumbnail in the iframe, it pops up on the parent page, not in the iframe.

so my idea was to place the thumbnail tag on the parent page, but hidden, and somehow make a tag that when I click on the thumbnail inside the iframe, it opens up the thumbnail tag on the parent page.

I hope this can help in solving my problem. Thanks so much :)

06-22-2010, 08:29 AM
I figured it out. thanks! :) God bless

06-22-2010, 08:31 AM
I do not know how you solved this, but I'm assuming you used:
<a href="javascript" target="_parent"><img src="img" /></a>