Search code examples
jqueryjquery-uidraggable

How do I make an element draggable in jQuery?


How do I make an element, e.g. a div, draggable using jQuery?


Solution

  • First load the jQuery UI:

    <link type="text/css" href="css/themename/jquery-ui-1.7.1.custom.css" rel="Stylesheet" />   
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
    

    Then use jQuery UI draggable method:

    <script type="text/javascript">
    $(function() {
        $("#b").draggable();
    });
    </script>