0

I was wondering why Jquery.onClick() won't let you follow links and open new windows.
I tried to "simulate" a click on a link like here but it won't work. Why?

$('#link').click();

Example: http://jsfiddle.net/wCRLE/5/

1
  • 1
    That's because it only triggers the event handlers set with javascript, and not native events Commented Jul 11, 2014 at 23:21

1 Answer 1

1

That would trigger any click event listeners you've added to the element, not trigger the native functionality.

You could do something similar by doing this:

window.open($('#link').attr('href'));

Example: http://jsfiddle.net/wCRLE/8/

On a side note, it's a good idea to avoid defining your click events inline with your HTML tag. I've modified your jsFiddle to show how you could do it using jQuery.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.