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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현