Search code examples
javascriptjqueryhrefmailto

Dynamically create and "click" a link with jQuery


I want to dynamically create an <a href="mailto:..."> element, then "click" it. All without modifying the page.

I'm trying this:

$('<a href="mailto:test@test.com">&nbsp;</a>').click();

...to no avail


Solution

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

    window.location = "mailto:test@test.com";