JavaScript/jQuery on click, confirm fires twice -


problem solved itself...

fyi: apparently was mac os or chromium engine bug after last system , browser updates problem disappeared appeared before. looks there not relevant jquery or javascript api.

i'll keep question few days , i'll delete later doesn't fit stackoverflow rules in such situation.


original post:

i have simple js confirm inside on click listener, in code below, no more requests (i.e. ajax, no duplicated js includes etc...).

the problem confirm dialog fired twice in browsers (i.e. chrome , opera @ mac os) , question is, did miss obvious or considerable bug of mentioned browsers? there workaround me prevent this? tried e.preventdefault(); no luck.

edit should've mention if there's no confirm('...'); within on click it's fired once (so 1 let check... in console occurs). confirm both logs appears twice in console, boolean in opposite order of clicking - sample - if i'll click cancel first , ok later console logs true first , false @ end... quite weird :s

versions:

  • jquery version: 1.11.3 - 1.12.0
  • chrome: 47.0.x (newest)
  • opera: 34.0.* (newest)

sample code (complete):

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>test...</title>     <script src="http://code.jquery.com/jquery-1.12.0.min.js"></script> </head> <body>      <div class="mybtn" data-field="one">take one</div>     <div class="mybtn" data-field="two">take two</div>     <div class="mybtn" data-field="three">take three</div>     <div class="mybtn" data-field="four">take four</div>      <script>         $(document).ready(function () {             $(document).on('click', '.mybtn', function () {                 console.log('let check...');                 var confirmation = confirm('are sure want ' + $(this).data('field') + '?');                 console.log(confirmation);             });         });     </script>  </body> </html> 

or click here: https://jsfiddle.net/gu58wwtg/1/

last edit: checked other possibilities bare approach (with pure js, no jquery) , prompt('...'); (which opens twice in reversed order) instead of confirm('...'); , problem still occurs, suspect bug, sorry, bothering you, , attention. i'll keep question, other guys can save time on frustrations ;)

i think should use .one

$(document).one('click', '.mybtn', function () { 

description: .one() attach handler event elements. handler executed @ once per element per event type.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -