Question

I am showing an alert when a span tag gets clicked. However after the first time, the alerts begin to appear one after the one as if they were being stored. I have no idea why this is happening, at first I thought it might be event bubbling but I tried stopPropagation() and still nothing, what am I missing?

Here's the span (it's inside a table):

<span href="#" class="button_like">copy Navigation URL</span>

js:

   $('span').click(function(e){
       stopBubbling(e);
       $(this).zclip({
           path: '/scripts/js/ZeroClipboard.swf',
           copy: $('#Txt2Copy').text(),
           afterCopy: function(){
               alert($('#Txt2Copy').text() + " was copied to clipboard");
           }
       });
       return false;
   });

function stopBubbling(e){
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}
Was it helpful?

Solution

Try using this , you don't need to bind the click function zclip will bind to the event.

   $(document).ready(function(){

        $('span').zclip({
               path: '/scripts/js/ZeroClipboard.swf',
               copy: $('#Txt2Copy').text(),
               afterCopy: function(){
               alert($('#Txt2Copy').text() + " was copied to clipboard");
               }
           });
    })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top