How to click on an image with a hyperlink using Javascript?

639 Views Asked by At

The HTML of the page I wish to use for this is as follows:

<A HREF= "http://www.example.com"
        TARGET="_new" status="Home Directory" title="Home Directory" 
        urn="Home Directory" FOLDER="http://www.example.com"><IMG align=textTop border="0" src="images/buttons/mywork.gif" alt="Select this icon to show your Home Folder" ></td>

How can I simulate a click on this hyperlinked image just using Javascript? I don't have edit privileges for this page so I need to work with what I have already got in the page (above)

3

There are 3 best solutions below

0
On

You can use firebug plugin for firefox and code your javascript from the console. Google chrome also has a console.

2
On

Give it an id for a start and then invoke using "apply"

var x = document.getElementById("linky");
x.onclick.apply(x);
1
On

I would use the jQuerify plug-in. Then type $('a').click(); in the Firebug console.