user1870773
user1870773

Reputation: 21

Programmatically press button or anchor tag

I am new to web programming. In html web page I want to press a button or anchor tag programmatically.

jquery api has trigger function which triggers call back function attached to a event, but my requirement is to programmatically press a button or link.

Upvotes: 1

Views: 177

Answers (2)

11684
11684

Reputation: 7517

I see you use jQuery.

$("#myElement").click();

Should so the trick.

Upvotes: 1

jonvuri
jonvuri

Reputation: 5930

Rather than trigger a click on a button or link, the better way to accomplish what you want to do is usually by visiting the link by setting window.location.href, or by calling the function or submitting the form that the button click would result in.

Upvotes: 1

Related Questions