Having trouble with jQuery UI draggable when using jQueryUI version 1.12.1?

Currently, I am diving into the world of jQuery UI. However, I am facing an issue with dragging the boxes that I have created using a combination of HTML and CSS. My setup includes HTML5 and CSS3 alongside jQuery version 1.12.1. Any suggestions or help would be greatly appreciated. Thank you in advance.

HTML code:

    <head>
        <title>jQueryUI Draggable</title>

        <link rel="stylesheet" type="text/css" href="normalize.css">
        <link rel="stylesheet" type="text/css" href="styles.css">

        <!--JqueryUI CSS-->
        <link href="jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css">

    </head>

    <body>

        <div class="container">
            <h1>jQueryUI Draggable</h1>

            <div id="box1" class="box">Box 1</div>
            <div id="box2" class="box">Box 2</div>
            <div id="box3" class="box">Box 3</div>
            <div id="box4" class="box">Box 4</div>
        </div>

        <!--If CDN Fails to load, serve up the local version-->
        <script src="js/jquery-3.2.0.min.js"></script>

        <script src="jquery-ui-1.12.1/jquery-ui.min.js"></script>

        <script src="script.js"></script>

    </body>

</html>

The normalize CSS file is a simple file for editing HTML as a default:

.box{
    height:200px;
    width:200px;
    display:inline-block;
    text-align: center;
    line-height: 200px;
    font-weight: bold;
    color:white;
    margin:0 20px;
}

#box1{
    background:lightblue;
}

#box2{
    background:lightgreen;
}

#box3{
    background:purple;
}

#box4{
    background:black;
}

.box:hover{
    cursor:pointer;
}

jQuery UI code:

$(function(){
    $('.box').draggable();
});

Answer №1

 $('.element').draggable();
.element{
    height:150px;
    width:150px;
    display:inline-block;
    text-align: center;
    line-height: 150px;
    font-weight: bold;
    color:white;
    margin:0 15px;
}

#ele1{
    background:lightblue;
}

#ele2{
    background:lightgreen;
}

#ele3{
    background:purple;
}

#ele4{
    background:black;
}

.element:hover{
    cursor:pointer;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>

 <div class="wrapper">
            <h1>jQueryUI Draggable Elements</h1>

            <div id="ele1" class="element">Element 1</div>
            <div id="ele2" class="element">Element 2</div>
            <div id="ele3" class="element">Element 3</div>
            <div id="ele4" class="element">Element 4</div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to reduce the spacing between subplots?

I am working on a subplot with multiple bar charts. Here is the code I have: fig = make_subplots(rows = 4, cols = 1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], ...

What is the process for altering the background color of a modal?

I'm trying to figure out how to change the background color of my modal once it's displayed, similar to this example: https://i.stack.imgur.com/fOUDZ.png. I want the background color to cover the entire page and not just the modal itself. When I ...

Express route not capturing entire request parameter due to regex issue

I am pretty sure that the issue lies in how express handles regex patterns in route definitions, although it might also be related to my pattern (I'm still new to regex, so please bear with me). In my express route definition, I am attempting to match ...

Comparing Nodes Armed with Clusters to Nodes Sporting Threads

Can you explain the key distinctions between node cluster and Threads agogo, including their respective advantages and disadvantages? From my understanding, Threads agogo creates a background thread while node cluster initiates a new process to run in th ...

Exploring Unicode in JavaScript to iterate through emojis with different skin tones

Currently, I am facing an issue where Javascript splits emojis with different skin colors into multiple characters instead of treating them as one. Emojis with a yellow skin color work fine and give me the desired results. For example: let emojis = [..." ...

Can state values be utilized as content for Meta tags?

I am looking for a way to display image previews and titles when sharing a page link. In order to achieve this, I am using the Nextjs Head Component. The necessary details are fetched on page load and used as content for the meta attributes. let campaign = ...

Utilizing Angular to nest a simple component within another component and display it exclusively on a targeted page or parent component

Currently, I am developing a mobile app using Ionic 3 and have created 2 components - Dumb or presentation components. The first component is the <ion-navbar>, which contains another component called <header-wallet-badge></header-wallet-badg ...

utilizing async/await without the need for babel-polyfill

Here is the code I am working with: @action async login(payload){ try { this.loginLoading = true const data = await request('/admin/login', { method: 'post', data: payload }) this.logined = ...

What is the best practice for importing React components?

In my experience with React, I've noticed two different ways of importing and extending components. The first way that I typically use is shown below. import React from 'react'; class SomeClass extends React.Component { //Some code } ...

Hear and register keypress in Angular service

I offer a dialog service Check it out below @Injectable() export class HomeDialogService { public constructor(private readonly dialogService: DialogService, private readonly userAgent: UserAgentService) {} @HostListener('document:keydown.escape ...

Discover the unseen: The ultimate guide to detecting visible objects in a (deferLoad) event

I'm utilizing the (deferLoad) method to load an image gallery in a more controlled manner. Is there any event available that can inform me about which items are currently visible? The main goal is to load a set of data along with an image path, and t ...

Having trouble getting the finally clause to work properly in Angular JS version 1.7

In my current project, I am utilizing Angular JS 1.7. Recently, I encountered an issue while using the finally clause within a promise: $http.put( url, null, { headers: { 'Content-Type': 'application/json' } } ).then( ...

Utilize filters on a dataset to display specific information

Front-end: const [filters, setFilters] = useState({ type: "", country:"", }); const onChangeFilterType = e => { const workingObject = {...filters}; workingObject.type = e.target.value; setFilters(workingObject); }; ...

Ways to resolve the responseJSON showing {error: "invalid_request", error_description: "Code parameter is missing"}

My current issue involves uploading files to Google Drive from my Vuejs and JavaScript web application. The request I send is returning an error. Upon checking, I noticed that the variable code is null, and even the variable window.location.search is empty ...

Connecting events across various browsers

In a function, I had to add an event to an element called newElement. To cater for different browsers like IE and Firefox, I checked the condition based on the attachEvent property (only works in IE). if ( typeof(newElement.attachEvent) != "undefined" ) { ...

When calling a method that has been created within a loop, it will always execute the last method of the

In my project, I am utilizing node version 0.8.8 in conjunction with express version 3.0. Within the codebase, there exists an object named checks, which contains various methods. Additionally, there is an empty object called middleware that needs to be p ...

Chrome not displaying fonts properly

Having a font issue in Chrome where specifying "Myriad Pro", Tahoma, Arial results in weird symbols. Works fine in FF, IE, and Safari. Using font-family: Tahoma, Arial; works for all browsers including Chrome. How can Myriad Pro be achieved for IE, FF, a ...

Creating multi-dimensional arrays using array lists with Axios and Vue.js

My knowledge of axios and JavaScript is limited, and I find myself struggling with creating a multi-dimensional array. 1. This is how I want my data to be structured : https://i.stack.imgur.com/kboNU.png userList: [ { ...

Is there a way to dynamically set the active panel of a JQuery Accordion when making a call?

Currently, I am faced with a scenario where I need to implement a greybox popup window using jQuery Accordion from the main page via links. I am curious to know if it is doable to specify a default active panel for the accordion when calling it. Below is ...

Is it possible to implement sandboxing for Node.js modules?

I've been diving into the world of Node.js and I have this exciting idea to create a cutting-edge MUD (online text-based game) using it. Traditionally, MUD games have predefined commands, skills, and spells that players can use to navigate through var ...