Enhance user experience with jQuery UI sortable and the ability to edit content in real

I am facing an issue with jquery sortable and contenteditable. The problem arises when I try to use jquery sortable along with contenteditable, as the contenteditable feature stops working. After searching on Stack Overflow, I found a solution. However, upon implementing it, a new problem surfaced - the sortable functionality ceases to work on mousedown event.

What could I be doing incorrectly?

Check out the Stack Overflow link for more insights

<div class="sortable">
  <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
    <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
    <div id="" style="background: #eee; width: 80%; margin: 10px auto; padding: 10px;">
    <p contenteditable="true" style="padding: 5px;">Add your text here.</p>  </div>
</div>

Initially, I used this snippet of code:

$('.sortable').sortable();

Then, I switched to the following code:

$('.sortable').on('onmousedown', function() {
        $(".sortable").sortable({
            cursor: 'move'
        });
    })

Answer №1

update the onmousedown event to mousedown

$('.sortable').on('mousedown', function() {
    $(".sortable").sortable({
        cursor: 'move'
    });
})

Additionally, when a paragraph is clicked, remove the sortable feature

 $('p').on('click', function() {
    $( ".sortable" ).sortable( "destroy" );
});

http://jsfiddle.net/fum9sf2m/

Answer №2

$(document).ready(function(){
     $( ".draggable" ).draggable();
}

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

Is there a way to upload images using jQuery Ajax with a Grails webservice?

I am trying to upload files to a webservice that is implemented using GRAILS. Normally, I can consume this web service using CURL with the following command: curl -X POST -H "Authorization: 53676c55f8014c5eb84624b49d9c9e74" -H "Content-Type: multipart/for ...

Troubleshooting ngFor in Angular 5

I'm currently working on a component that needs to display data fetched from the server. export class CommerceComponent implements OnInit { dealList; ngOnInit() { this.getDeals(); } getDeals(){ this.gatewayService.se ...

Is there a way to transfer a value set from one tpl file to another tpl file in cscart using smarty template engine?

I am trying to retrieve the value of a variable set using an input tag from one tpl file. Here is the input tag in A.tpl file: <input type="checkbox" class="checkbox" name="payment_data[processor_params][enable_addbillcard]" id="optional_enable_addbil ...

How can Play framework be used to display static HTML pages with static JavaScript and CSS files?

I'm currently exploring options for rendering or routing to static web apps stored in the Play's public folder. Here is my project structure: myapp + app + conf + modules + public | + webapp1 | + css | + ...

Struggling to connect with PouchDB within my HTML-based Web application

I am looking to integrate pouchDB into my WebApp so that upon clicking a button, the data from a JSON file will be saved to pouchDB. In the initial stage in my index.html, I included the following: <script type="module" src="pouchdb/packa ...

Steps to inject HTML content via id using a technology such as AngularJS' ng-include

My current project involves using AngularJS to compile a directive into the main page. This directive contains a series of buttons that dynamically change based on its internal state. I am interested in relocating these buttons to a menu-bar within the pag ...

ECharts - Version 3.1.6 Event Plugin

I am looking for advice regarding the management of two charts with reference to echars from Baidu (version 3.1.6). Is there a way to control both charts by engaging in a click event on one of them? In simpler terms, how can I capture and respond to the c ...

How can we align the Recaptcha and Send button with the text box in a DIV using CSS exclusively?

Struggling to line up my send button and recaptcha with the end of the text box in a contact form in a responsive manner. I've spent days trying to make it work without success. Check out my jsfiddle here: Example Here's the current CSS: /*cust ...

Convert a list into a hierarchical structure of nested objects

Working with angular, I aim to display a nested tree structure of folders in an HTML format like below: <div id="tree"> <ul> <li ng-repeat='folder in folderList' ng-include="'/templates/tree-renderer.html'" ...

Utilizing Font Awesome icons dynamically presents challenges when integrating with SVG & JavaScript

Recently, I started using the new JS&SVG implementation of font-awesome's v5 icons. It seems to be working perfectly for icons (such as <i class='fas fa-home'></i>) that are already present in the DOM at page load. The <i& ...

What's the point of repeatedly confirming prompts?

I am using Jquery ajax call to delete data from my HTML table. Everything works fine, but the alert message keeps showing repeatedly. What could I be doing wrong? Delete button "<a href='#my_modal' class='delete-Record'>Del ...

Tips for swapping images as a webpage is scrolled [using HTML and JavaScript]

Hi there, I am looking to make some changes to a JavaScript code that will switch out a fixed image depending on the user's scrolling behavior. For example, when the page loads, the image should be displayed on the right side. As the user scrolls down ...

Stylish CSS: Jagged 3-dimensional rotated text

Have a look at this Codepen to see the issue. As the text moves into the background, more aliasing appears. A screenshot taken in Chrome on macOS (similar appearance in FF & Safari): https://i.sstatic.net/n746I.png I've experimented with different ...

Press the button to switch between displaying one component and hiding another component within reactjs

I am working on a project with two distinct buttons: one for grid view and another for list view. <button onClick={() => setClassName('jsGridView')} title="Grid View" > <IoGrid className="active" s ...

"Uh-oh! Encountered a new unexpected runtime error. Can't seem

While working on my portfolio in Next.js, I encountered an issue. I added a header to display on all pages by placing it in _app.js without making any changes to _document.js. Here is the error message: Unhandled Runtime Error Error: No router instance fo ...

Issues arise when attempting to utilize a jQuery function to call an asp.net web method

In my ASP.NET project, I have a web method that looks like this: [WebMethod] public string getCurrentDate() { return DateTime.Now.ToString(); } My jQuery ajax call to this web method is as follows: $.ajax({ type: "POST", url: "jqueryAjax/Defau ...

Troubleshooting Laravel: Ajax Call for Deleting Records not Functioning Properly on Button Click Event

I've encountered an issue with deleting a record from an ajax call in a Laravel CRUD application. The click event doesn't seem to be triggered, resulting in the delete function not working as intended. Below is the relevant code snippet. web.php ...

Retrieve the value of the option that has been selected

I've been searching tirelessly, but I just can't seem to find the answer online or figure out the correct code on my own. Although I did manage to make it work with jQuery, I need to switch over to using YUI 2.7. So, what exactly am I trying to ...

Halting Execution After Placing an Object in Three.js Scene with Javascript

It seems like a simple task, but I've been struggling with it for days. How can I add objects to a scene with a pause between each addition? Inside a loop{ I call the make_obj function() then I call the wait function() } The issue is that the pr ...

What does the error message "unsupported command-line flag" in Chrome mean for Protractor?

Recently jumping on the Protractor bandwagon, I found myself facing an issue while running my tests on Chrome (an error message appears below the address bar in the browser): A worrisome warning popped up saying something about '--ignore-certificat ...