0

I am trying to setup an event function to react on clicked links in a menu, but unfortunately its not working.

This is JS code:

$('#menu a').click(function() {
    return "Do you really want to leave now?";
});

And the HTML bit:

<div id="menu">
    <a href="#"> Link1 </a>
    <a href="#"> Link2 </a>
</div>

It seems quite straight forward, but unfortunately not working.

JS fiddle: http://jsfiddle.net/Kdvk3/6/

JavaCake
  • 4,075
  • 14
  • 62
  • 125

1 Answers1

4

You need you use an alert() or confirm(), like this:

$('#menu a').click(function() {
    return confirm("Do you really want to leave now?");
});
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • Normally i use `return "Do you really want to leave now?";` to create the popup alert automagically. Why is it not possible in this scenario? – JavaCake Jan 24 '13 at 18:34
  • 2
    I don't know how this would work auto-magically. I would be interested in understanding if you are using some kind of custom javascript that would do such a thing. – Mike Brant Jan 24 '13 at 18:35
  • I got it working prior to this answer http://stackoverflow.com/a/4041753/531203, but it did not work in this scenario where im not using bind. Simply using jQuery. – JavaCake Jan 24 '13 at 18:38