Javascript / Jquery, open a link with a REL tag as if it were clicked?

Rick picture Rick · Apr 19, 2011 · Viewed 7.1k times · Source

The designer that I am working with on a project implemented a pop-up so that it is called when a static link is clicked like

<a href="#" rel="#dialog">Testing Dialog</a>

Of course, I don't want it as a static link as I have to do things to it before it is shown to the user so I am wondering if anyone knows of a way to make a call with Javascript to do the same thing as if the link above were clicked by the user? Any advice is greatly appreciated

Answer

karim79 picture karim79 · Apr 19, 2011

If I understand correctly, with jQuery:

$("a[rel='dialog']").click();

or:

$("a[rel='dialog']").trigger("click");

Demo: http://jsfiddle.net/karim79/fc6Yk/