markzzz
markzzz

Reputation: 48015

jQuery + jQuery Mobile = Calling handlers two times?

I inserted jQuery (1.8.2) and jQuery mobile (1.1.1) on my web application. Now, if I create this simple handler :

$('.pulsante-menu').click(function () {
    console.log("ooo");
});

and I click the link, I see that console message twice! How can I fix it?

This is my code!

Upvotes: 0

Views: 58

Answers (3)

Percutio
Percutio

Reputation: 954

Move your script in your <head> element or in a separate JavaScript file. Or try using pageinit. Reason why it does this is explained in this post on jQuery.com.

Upvotes: 3

gpojd
gpojd

Reputation: 23085

You have the handler defined twice in your fiddle, once in the JS section and once in a script tag in the HTML section. Remove one of them and it should work.

Check my updated fiddle.

HTML:

<head>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
  <script src="http://jquerymobile.com/demos/1.1.1/js/jquery.mobile-1.1.1.js" type="text/javascript"></script>
</head>
<body>
  <a href="#" class="prova">Link</a>
</body>

JavaScript:

$('.prova').click(function () {
    console.log("ooo");
    return false; // stopPropagation and preventDefault
});

Upvotes: 0

Marcelo Biffara
Marcelo Biffara

Reputation: 831

You could try something like this.

$('.pulsante-menu').click(function (e) {
    e.stopPropagation();
    console.log("ooo");
});

Upvotes: 0

Related Questions