tags:

views:

100

answers:

2

I have this bit of code but it's not doing what I want.

Whenever someone clicks on a mailto link, a popup will display the following message 'This is the message.' So far nothing is happening

$('a[href^=mailto:]').click(function () { 
    var x=window.confirm('This is the message.');
    var val = false;
    if (x)
        val = true;
    else
        val = false;
    return val;

});
+1  A: 

You need quotes

  $('a[href^="mailto:"]')

And while we're at it how about just:

 var x=window.confirm('This is the message.');
 return x;

for the body of the function?

Vincent Ramdhanie
+2  A: 

Try this:

$('a[href^="mailto:"]').click(function(){
    return confirm('This is the message.');
});
a432511
That's what I needed to get this working, thank you.
kylex
You don't **need** the quotes, quotes are always optional. You just need to escape the colon (or other special characters) as such: `$("a[href^=mailto\\:]");`. http://docs.jquery.com/Selectors#Special_characters_in_selectors
Kevin Peno
True. I think this is just the easiest way.
a432511