In my jQuery Mobile application, I am trying to click a mailto link programmatically but having no success.
Here is the HTML code:
<section id="mensen" data-role="page">
<div data-role="content" class="content">
<a id="emailLink" href="mailto:123@123.com">This is the email link</a>
</div>
</section>
The jQuery code is :
$(document).ready(function()
{
$('#emailLink').click();
})
The link functions normally and the default email client is launched if clicked directly but nothing happens programmatically.
yes indeed, but this will work
edited: (“why?” comment)
because a query done with jquery $(…) returns an array/object of elements.
we have to use the index [0] (expecting only one because its an id) in order to call the .click function of the link object and not on the jquery result array.
btw i don’t expect the array to have that functionthe jquery result array is expected to have a .get(…) function to retrieve elements from the result