0

I am trying to go to a specific link with jquery but my code does not do it

None of this works

$("<a class='tab-link' href='cnn.com'>cnn</a>").trigger('click');
$("<a class='tab-link' href='cnn.com'>cnn</a>").click();

This is the fiddle https://jsfiddle.net/hmkLwme9/7/

The link i want to visit must have the class tab-link

How can i do this in jquery?

Le Qs
  • 785
  • 2
  • 9
  • 26

1 Answers1

0

First of all, you need to create this element and include to DOM. For example:

$("<a class='tab-link' href='cnn.com' onClick=\"alert('hello');\">cnn</a>").appendTo("body").trigger('click');

Check it on https://jsfiddle.net/hmkLwme9/8/

RafelSanso
  • 33
  • 6