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

Thumbnail Carousel Caption in Bootstrap 3

Is it possible to create a Bootstrap 3 carousel where the image changes when the mouse cursor hovers over the thumbnail under the carousel? Currently, I have a setup with the carousel and thumbnails below it. Typically in Bootstrap, the image changes autom ...

What is causing the breakdown in communication between my server and client?

While utilizing React and an Express server for the backend, I am facing an issue where my API call to server.js is not going through. The React client is running on port 3001 and the server on port 3002. The fetch code in CreateAccount.js is as follows: ...

When setting the form action attribute in jQuery, the parameter being passed may be null

My goal is to redirect my form action to another page with a URL parameter. Here's the code I'm using: ui.setFormActionToTargetPage = function () { $('form').get(0).setAttribute('action', 'myTargetPage.html?id=' ...

Using TailwindCSS with Vite in a vanilla JavaScript project: A step-by-step guide

As a beginner, I feel like I'm losing my mind trying to figure this out. I've watched countless tutorials and read through numerous documents, but still can't seem to get it working. Does anyone have any advice on how to successfully integra ...

Is it wise to question the validity of req.body in express.js?

https://expressjs.com/en/4x/api.html mentions It is crucial to validate all properties and values in the req.body object as they are derived from user input. Any operation performed on this object should be validated to prevent security risks. For instan ...

Ensure that the form is submitted when a checkbox is clicked, while also maintaining the native browser

My form contains a text input field and a checkbox. The text input must not be left empty when the form is submitted, which is why the required attribute is used. I want the form to be submitted every time the checkbox is clicked, while still maintaining ...

Scale transformation - I am aiming for it to exceed the limits, yet it remains contained within

Currently, I am working on enhancing my carousel by implementing a zoom effect when hovering over the images. However, I have encountered an issue where the image gets hidden within the div container and doesn't overflow as expected. I tried adjusting ...

Create a specific website link for searching on YouTube

Is there a way to generate a YouTube URL using JavaScript or PHP that searches for videos on a specific user account and displays the best title match at the top of the search results? This is the code I am currently using: <!DOCTYPE html> <head ...

Express bodyParser may encounter difficulties in parsing data sent from Internet Explorer

After creating a server app with Node and Express 4, I utilized jQuery for the front-end. An Ajax call was set up to send data via POST to the server: $.ajax({ cache: false, type: 'POST', url: Config.API_ENDPOINT_REGISTRATION, ...

Mysterious CSS "manifestation" perplexes Chrome while evading Firefox's gaze

There seems to be an issue with the jQuery plugin on this demo page: If you access it using Firefox, you'll notice that the social sharing buttons are visible and functioning properly. However, in Chrome, there appears to be a peculiar CSS computatio ...

How can I tally the frequency of characters in a given string using Javascript and output them as numerical values?

I am in the process of tallying the frequency of each individual character within a given string and representing them as numbers. For example, let's consider the string "HelloWorld". HELLOWORLD There is one H - so 1 should be displayed with H remov ...

Customizing the appearance of default UI elements in asp.net

Recently, I was tasked with creating an image uploading function for a web application using asp.net. To start off, I utilized the standard input asp.net button along with the browse and filename label. The implementation of this code is quite straightforw ...

Continue scrolling for additional information to load

My HTML page is quite lengthy, filled with content within li tags. I am looking for a way to avoid loading all of them at once and instead have the page load approximately 10 li tags when the user scrolls down to read further. The goal is to pre-load 15 li ...

How to use CSS to dynamically adjust the maximum width of an overflow container based on its children's content

I have a container with an overflowing <div> that displays multiple <ul> <li> lists. Each list always contains the same number of bordered <li> items, resembling a table. However, there may be instances where a <ul> has only ...

Instructions on adjusting the height of a flexbox container to utilize the available space

I am facing a challenge in grasping the interaction between flexbox containers and other elements on a webpage. When I have only a flexbox on my page, everything works smoothly. However, when I introduce other elements, things start acting strangely. It se ...

What is the best way to add a listener for a modification of innerHTML within a <span>?

How can I detect changes inside a particular <span> element in order to attach a handler, but so far have been unsuccessful? Below is the HTML snippet: <span class="pad-truck-number-position"><?php echo $_SESSION['truckId']; ?> ...

Validating File Inputs with jQueryThis validation script is specifically designed

My form has textboxes, drop down lists, and a file input that I am validating using jQuery. Although everything works perfectly with the exception of the file input. The default error message is displayed instead of the custom one, and the extension part d ...

Obtain date and currency formatting preferences

How can I retrieve the user's preferences for date and currency formats using JavaScript? ...

Retrieving JSON data through HttpClient in Angular 7

I am attempting to retrieve information from this specific URL. The data obtained from this URL is in JSON format. This particular file is named data.services.ts: import { Injectable } from '@angular/core'; import { HttpClient } from '@an ...

A guide on incorporating Vue.js into a Hexo static site generator

Exploring the use of vue.js within my hexo theme has sparked my interest. Can anyone guide me on how to compile my .vue files for both development and production environments? It's worth mentioning that I intend for vue.js to operate on the client sid ...