Eddie Domingues Eddie Domingues - 6 months ago 27
jQuery Question

Jquery draggable not working 2

So I'm trying to make an element draggable with jquery but it's not working here is the code

<html>
<head>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<style>
#console {
background-color: #000000;
}
</style>
</head>
<body>
<div id="console">

</div>
<script>
$(function() {
$( "#draggable" ).draggable();
});
</script>
</body>
</html>

Answer

You need an element to drag. There isn't any such element with id draggable for which you have instantiated dragging. I presume you want to drag div with id console and hence you need to initialize draggable on that particular element like $( "#console" ).draggable();. Below is the working snippet

$(function() {
  $("#console").draggable();
});
#console {
  background-color: #000000;
  width: 300px;
  height: 300px;
}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<div id="console">
</div>

Comments