javascript - How to simulate the clicking of a hyperlink? -


I have 2 links a1 and a2, and a2 is hidden when the user clicks on a1, then i am on a2 I want to emulate clicking. How can this be done with jQuery?

It depends on what it means by "simulating the clicks of A2" .

Assuming that the a1 and a2 are id attributes, if you think that you want to trigger the jQuery handler on that element, You can do so:

  $ ("# a1"). Click (function () {$ ("# a2"). Trigger ('click');});  

If you do not bubble the event or trigger without triggering default behavior, then do this:

  $ ("# a1 "). Function () {$ ("# a2"). Trigger handler ('click');});  

But if you really want to move to Affiliate href , then you will need it:

  $ (" # A1 "). Click (function () {window.location = $ ("# a2"). Attr ('href');});  

or

  $ ("# a1"). Click (function () {window.location = document.getElementById ('a2'). Href;});  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -