Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:52:42+00:00 2026-06-09T03:52:42+00:00

I have jquery draggable attached to a DIV container, each of its child elements

  • 0

I have jquery draggable attached to a DIV container, each of its child elements has a click event, how do I prevent the child event from firing when I drag the main parent container.

I only want to fire the child event when I click on it, not when I drag the whole thing.

I have made a demo: http://jsfiddle.net/sygad/RgdPq/1/

Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:52:43+00:00Added an answer on June 9, 2026 at 3:52 am

    You can use a temp variable to track the drag status and then change from the click event to the mouseup event like this jsFiddle example.

    jQuery

    var bodyWidth = $(window).width();
    var bodyHeight = $(window).height();
    var dragging = false;
    $("#container").draggable({
        containment: "window",
        start: function() {
            dragging = true;
            $(this).addClass('dragged')
        },
        stop: function() {
            dragging = false;
            $(this).removeClass('dragged')
        }
    });
    
    $('.box').mouseup(function() {
        if (!dragging) {
            //If there is already a new box present, remove it
            if ($('.newBox').length) {
                $('.newBox').remove();
            }
    
            //Get the offset of THIS box we just clicked
            var thisOffset = getOffset(this)
    
            //Get its left & top value
            var newBoxLeft = thisOffset.left;
            var newBoxTop = thisOffset.top;
    
            //Full size box will be 75% width & height of viewport
            var newBoxFinalWidth = bodyWidth * 0.75;
            var newBoxFinalHeight = bodyHeight * 0.75;
    
            //Full size box will be positioned center/center on the screen
            var newBoxDestLeft = (bodyWidth - newBoxFinalWidth) / 2;
            var newBoxDestTop = (bodyHeight - newBoxFinalHeight) / 2;
    
            //Create our new box
            var newBox = '<div class="newBox clickOut"></div>'
    
            //Add it to the DOM
            $('body').append(newBox);
    
            //Position it to overlay the box we just clicked
            $('.newBox').css({
                'left': newBoxLeft,
                'top': newBoxTop
            })
    
            //Animate it from the orig box position to its final width/height & left/top
            $('.newBox').delay(100).animate({
                'width': newBoxFinalWidth,
                'height': newBoxFinalHeight,
                'left': newBoxDestLeft,
                'top': newBoxDestTop
            }, 2000, 'easeOutExpo')
        }
    })
    
    //Clickout function
    $(document).click(function(e) { /*if parent of this click is NOT clickout AND this click is NOT clickout then hide stuff*/
        if ($(e.target).parents().is('.clickOut') == false && $(e.target).is('.clickOut') == false) {
            clickOut();
        }
    });
    
    function clickOut() {
        $('.newBox').remove()
    }
    
    function getOffset(item) {
        var cssOffset = $(item).offset();
        var cssLeft = parseInt(cssOffset.left);
        var cssTop = parseInt(cssOffset.top);
    
        return {
            'left': cssLeft,
            'top': cssTop
        };
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery draggable container div with a side scroll bar that should
I have a div, which has jQuery UI Draggable applied. What I want to
I have a jquery ui draggable div, and the HTML contents do not behave
I have a jquery draggable div and i want the position to be saved
I have a div container with a text that has been previously typed in
Possible Duplicate: jQuery UI draggable to smaller droppable I have a draggable div and
I have two li elements which are jQuery draggable. When I drag and drop
I have a partial view that has a number of Div's, each are set
I have a little problem with the jQuery Draggable IFrameFix. I have a container
I have multiple element that are jquery ui draggable, these elements can also be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.