Dynamically create and "click" a link with jQuery

.click() work with a DOM, not jQuery object

it should be:

$('<a href="mailto:[email protected]"></a>')[0].click();

To make it work with jQuery, you first need to select the DOM element inside the jQuery object.

$('body').append('<a id="link" href="mailto:[email protected]">&nbsp;</a>');
$('#link')[0].click();

Notice the [0]

fiddle: https://jsfiddle.net/fkwhvvhk/


Its not jquery, but it works just fine.

var link = document.createElement('a');
link.href = url;
document.body.appendChild(link);
link.click();    

Clicking on a link means changing window.location, so how about

window.location = "mailto:[email protected]";