You need to use an actual selector, such as a[href^="mailto"]
Add JS alert to mailto links
-
29-07-2022 - |
Question
Is there a way with javascript to automatically have the page look for any mailto links and then have it fire off an alert when a user clicks on the mailto link?
I currently have this:
HTML:
<a href="mailto:nachomomma@notyourdomain.com">Email Link</a>
Javascript:
$(document).on('click','mailto',
function() {
alert('This is some alert text');
});
But that doesn't seem to work. Not too sure if I am going about this the correct way or if it's even possible.
Solution
OTHER TIPS
make like this
$(document).ready(function() {
$("a[href^='mailto:']").click(function(){
alert('This is some alert text');
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow