views:

832

answers:

5

In jQuery trigger('click') and click() seem to only trigger the onclick event. I want to simulate a click of an a tag without an onclick event.

What I am trying to reach is to display a lightbox upon landing. The lightbox is attached to an a tag which needs to be clicked.

Any ideas?

A: 

Try this:

window.location = $('a#go').attr('href')

CodeJoust
A: 

The onclick event is all there is. If it bubbles all the way up without getting stopped, it will bring you to the location of the link.

You might need something to stop it from bubbling. You can either return false; or e.preventDefault() to stop the form from submitting, and you can use e.stopPropagation() and e.stopImmediatePropagation() in order to stop it from bubbling.

Chances are, there is a way to activate the lightbox plugin without "fake-clicking" a link though.

Alex Sexton
A: 

Solved it. Slimbox for mootools supports calling the lightbox directly without needing a link.

eakkas
A: 

Most lightboxes do have support to launch them via JavaScript as well as clicking from a link. Slimbox is definitely a nice lightbox, good choice!

Shawn Steward
+1  A: 

still, to answer your original question, at least insofar as mootools is concerned: you can simulate a click / fire the function set to handle it (if any) via this:

$("someid").fireEvent("click");
Dimitar Christoff