Cancel event bubbling from jquery draggable to click on child element on drag stopPreventing click event with jQuery drag and drophow to avoid jQuery UI draggable from also triggering click eventBlur event stops click event from working?Draggable cancel triggering blur eventjQuery clickable element nested in draggable oneJquery drag and drop - click event registers on dropJquery drag and drop - set clickable region in draggable on dropjquery ui drag event to cancel click eventStop event propagation from jquery Draggable stop to onclickHow to stop click event on drag with using angular2-draggable library?

What is the practical impact of using System.Random which is not cryptographically random?

How to load files as a quickfix window at start-up

How were US credit cards verified in-store in the 1980's?

Squares inside a square

Doesn't the concept of marginal utility speak to a cardinal utility function?

Can a system of three stars exist?

Why is Mitch McConnell blocking nominees to the Federal Election Commission?

Displaying Time in HH:MM Format

Could a simple hospital oxygen mask protect from aerosol poison?

Should we run PBKDF2 for every plaintext to be protected or should we run PBKDF2 only once?

Single vs Multiple Try Catch

Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?

Underbrace in equation

Can authors email you PDFs of their textbook for free?

Can a human variant take proficiency in initiative?

Is it good practice to speed up and slow down where not written in a song?

Ways you can end up paying interest on a credit card if you pay the full amount back in due time

How does the search space affect the speed of an ILP solver?

Was there an original & definitive use of alternate dimensions/realities in fiction?

Fishing from underwater domes

Ideas behind the 8.Bd3 line in the 4.Ng5 Two Knights Defense

How to correctly set logical high level on PS/2 port?

'spazieren' - walking in a silly and affected manner?

Why don't "echo -e" commands seem to produce the right output?



Cancel event bubbling from jquery draggable to click on child element on drag stop


Preventing click event with jQuery drag and drophow to avoid jQuery UI draggable from also triggering click eventBlur event stops click event from working?Draggable cancel triggering blur eventjQuery clickable element nested in draggable oneJquery drag and drop - click event registers on dropJquery drag and drop - set clickable region in draggable on dropjquery ui drag event to cancel click eventStop event propagation from jquery Draggable stop to onclickHow to stop click event on drag with using angular2-draggable library?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a draggable div with a clickable tag within it:



<div id='myDiv'>
<a id='mylabel' onclick="alert('i am clicked')">some text</a>
</div>
$("#myDiv").draggable(
stop: function(e)
//want to cancel the click event on the nested a element
//e.preventDefault(); ??
//e.cancelBubble(); ??

);


When I stop dragging, the click event fires, which I don't want. I tried preventDefault and cancel on the stop drop event but the click event still fires. Any ideas anyone?










share|improve this question
























  • Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

    – varun agarwal
    Mar 28 at 2:16

















0















I have a draggable div with a clickable tag within it:



<div id='myDiv'>
<a id='mylabel' onclick="alert('i am clicked')">some text</a>
</div>
$("#myDiv").draggable(
stop: function(e)
//want to cancel the click event on the nested a element
//e.preventDefault(); ??
//e.cancelBubble(); ??

);


When I stop dragging, the click event fires, which I don't want. I tried preventDefault and cancel on the stop drop event but the click event still fires. Any ideas anyone?










share|improve this question
























  • Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

    – varun agarwal
    Mar 28 at 2:16













0












0








0








I have a draggable div with a clickable tag within it:



<div id='myDiv'>
<a id='mylabel' onclick="alert('i am clicked')">some text</a>
</div>
$("#myDiv").draggable(
stop: function(e)
//want to cancel the click event on the nested a element
//e.preventDefault(); ??
//e.cancelBubble(); ??

);


When I stop dragging, the click event fires, which I don't want. I tried preventDefault and cancel on the stop drop event but the click event still fires. Any ideas anyone?










share|improve this question














I have a draggable div with a clickable tag within it:



<div id='myDiv'>
<a id='mylabel' onclick="alert('i am clicked')">some text</a>
</div>
$("#myDiv").draggable(
stop: function(e)
//want to cancel the click event on the nested a element
//e.preventDefault(); ??
//e.cancelBubble(); ??

);


When I stop dragging, the click event fires, which I don't want. I tried preventDefault and cancel on the stop drop event but the click event still fires. Any ideas anyone?







javascript jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 0:35









ProgramnikProgramnik

8436 silver badges11 bronze badges




8436 silver badges11 bronze badges















  • Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

    – varun agarwal
    Mar 28 at 2:16

















  • Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

    – varun agarwal
    Mar 28 at 2:16
















Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

– varun agarwal
Mar 28 at 2:16





Sorry I didnt see the structure before. Typically events go bottom up, so if you are trying to drag the a element, the click will be fired. The only way to make it work is to put a event.preventDefault on the click which is as good as not putting a click listener on that element.

– varun agarwal
Mar 28 at 2:16












1 Answer
1






active

oldest

votes


















0















I figured it out. The trick is to attach a click event to the draggable div like so:



$("#myDiv").click(event.stopPropagation());


Because dragging the div also invokes a click event, which then propagates to the child a tag, the stop drag event is the wrong thing to stop. Removing click propagation is the way to go.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388514%2fcancel-event-bubbling-from-jquery-draggable-to-click-on-child-element-on-drag-st%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    I figured it out. The trick is to attach a click event to the draggable div like so:



    $("#myDiv").click(event.stopPropagation());


    Because dragging the div also invokes a click event, which then propagates to the child a tag, the stop drag event is the wrong thing to stop. Removing click propagation is the way to go.






    share|improve this answer





























      0















      I figured it out. The trick is to attach a click event to the draggable div like so:



      $("#myDiv").click(event.stopPropagation());


      Because dragging the div also invokes a click event, which then propagates to the child a tag, the stop drag event is the wrong thing to stop. Removing click propagation is the way to go.






      share|improve this answer



























        0














        0










        0









        I figured it out. The trick is to attach a click event to the draggable div like so:



        $("#myDiv").click(event.stopPropagation());


        Because dragging the div also invokes a click event, which then propagates to the child a tag, the stop drag event is the wrong thing to stop. Removing click propagation is the way to go.






        share|improve this answer













        I figured it out. The trick is to attach a click event to the draggable div like so:



        $("#myDiv").click(event.stopPropagation());


        Because dragging the div also invokes a click event, which then propagates to the child a tag, the stop drag event is the wrong thing to stop. Removing click propagation is the way to go.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 2:15









        ProgramnikProgramnik

        8436 silver badges11 bronze badges




        8436 silver badges11 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388514%2fcancel-event-bubbling-from-jquery-draggable-to-click-on-child-element-on-drag-st%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript