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

  • SEARCH
  • Home
  • 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 8678511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:44:24+00:00 2026-06-12T20:44:24+00:00

I have the following code ( jsfiddled ). I want to use red SVG

  • 0

I have the following code (jsfiddled). I want to use red SVG rectangle as a handle for draggable div element, but because the SVG element is not a child of div, it is not possible. The idea is to let the handle (red rect) fire drag event of div and when div is being dragged, the code updates position of red SVG rectangle. How can I get SVG rectangle to act as drag handle for the div (so that SVG element is not a child of div element)?

I have tested to make SVG a child of div and used SVG rect as handle, and this worked normally. When I dragged SVG rect, the div and SVG rect were moved while dragging. But the problem is that also SVG element itself is dragged. But I don’t want that SVG element itself is moved while dragging, only rect and div.

EDIT: Some sort of triggering drag event of div when pressing mouse on svg rect comes to my mind as a possible solution, but not tested yet.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>jQuery UI Draggable - Handles</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
        <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
        <style>
            #draggable { position:absolute; opacity:0.5;
    width: 100px; height: 100px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
           #draggable p { cursor: move; }
           #draggable {left:30px;top:0px;z-index:1}
        </style>
        <script>
            $(function() {
                $( "#draggable" ).draggable({ handle: "p" });
                $( "div, p" ).disableSelection();
            });
        </script>
    </head>
    <body>
        <div id="draggable" class="ui-widget-content">
            <p class="ui-widget-header">I can be dragged only by this handle</p>
        </div>
        <svg width="500" height="500" style="position:absolute;z-index:-1">
            <rect x="0" y="0" width="100" height="100" fill="#FF8888"/>
        </svg>
    </body>
</html>
  • 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-12T20:44:25+00:00Added an answer on June 12, 2026 at 8:44 pm

    After some testing I ended up to use combination of div.trigger(e) and updating SVG rect’s transform attribute in draggable div’s drag-function this jsfiddled way.

    The key point is the following code, which triggers div’s drag event when pressing mouse on SVG path element:

    $("#path_1").mousedown(function(e) {
        $( "#div_1" ).trigger(e);
    });
    

    And the other key point is the following, which updates SVG path element’s transform attribute to achieve movement:

    drag: function(e, ui)
    {
        var x=$( "#div_1" )[0].style.left;
        var y=$( "#div_1" )[0].style.top;
        x = parseInt(x);
        y = parseInt(y);
        $( "#path_1" ).attr("transform", "translate("+x+","+y+")");
    }
    

    It relies on pointer-events:none in div, so not works in Opera, but in other new browsers yes. There is a hack to allow pointer-events:none, but better to wait that all newest browsers allow it natively. And pointer-events is not problem in the question’s example because red rectangle is not fully below div.

    Jsfiddle example can be extended to eg. make a selection rectangle functionality for SVG elements, if you want to use jQuery Draggable plugin for dragging SVG’s graphical objects and want to use divs as selection rectangles. (Other possible solution to selection rectangles is to use two SVG root elements, one for selection rectangles and one for actual shapes.)

    And using setTimeout() we can force that always when div is moved, also SVG path is moved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following html code: <div id=element> Qwerty Foo Bar <span style=color:
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code: <div style=border:4px solid black;width:100%;height:100px;position:fixed;left:250px;> out of bound :( </div> I
I have following code (live: http://jsfiddle.net/xyZY8/1/ ): var str = '<div>hello</div><ul><li>Some text...</li>' + '<li>second
I have the following code. I want to add two input fields together and
I have the following code but when I submit the from the page redirects.
I have the following HTML code: <div id=inner> <div id=wrap> <img src=images/thumb/3.jpeg/> </div> </div>
Background I have the following html code: <div id=parent> <div id=child> I'm the child!
I have following html and css code in which I want <a> tag to

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.