Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:36+00:00 2026-05-26T06:45:36+00:00

I am trying to do html5 dragndrop on my html5/css chessboard using unicode pieces

  • 0

I am trying to do html5 dragndrop on my html5/css chessboard using unicode pieces but have a problem at the moment with it.
On dragging & dropping the whole ‘li’ element seems to move & on drop this disrupts the board.

This can be seen on the chess WordPress site at:

http://www.buryknightschess.org.uk/play-chess/

(As can be seen I asked for help with this on SitePoint Forums but haven’t had a reply to help yet from there).

Possibly I somehow need just to make the unicode chess pieces draggable & not the whole chess square (<li></li>).

I shall keep trying to fix this but meanwhile I would greatly appreciate any advice to help with this html5 dragndrop issue. I look forward to helpful replies, many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:45:36+00:00Added an answer on May 26, 2026 at 6:45 am

    The reason the <li/> is being moved (thus rearranging the chess board) is because in your drop function is calling appendChild:

    function drop(event) {
        var element = event.dataTransfer.getData("Text");
    
        // This changes the DOM
        event.target.appendChild(document.getElementById(element));
        event.stopPropagation();
    
        return false;
    }
    

    Instead of moving that actual DOM node, the drop function should copy the innerHTML of the node that’s being dragged. Here’s how the new drop would look function:

    function drop(event) {
        var coordinate = event.dataTransfer.getData("Text");
        var element = document.getElementById(coordinate);
    
        event.target.innerHTML = element.innerHTML; // Moving piece to new cell
        element.innerHTML = ""; // Clearing old cell
    
        event.stopPropagation(); // Consider using `event.preventDefault` instead
    
        return false;
    }
    

    Also, I’d consider using event.preventDfault instead of event.stopPropagation. This makes it possible to add new drop listeners to the board or one of its parents. For example you may want to add a drop listener to the document body to handle the case where a user tries to drag a piece off the board.

    As general remark, have you considering using jQueryUI draggable and droppable libraries? You’d be able to support much richer drag/drop interactions such as snap-to-grid movement and delayed starts. Also, HTML5 drag-and-drop is typically used to allow users to drag files from their OS desktop onto the a web page. The way your using it is totally fine, it’s just a little strange.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn and use html5 and have a basic layout but
I am trying to control HTML5 videos using JQuery. I have two clips in
I am trying to play mp4 video using html5 video tag. But in FF
I'm trying to get an html5 demo page working on Android 2.1, have tried
I am trying to code a clean html5 website. I am using the html5
I'm trying to create a simple WebSocket example using the HTML5/JS API. Based on
In HTML5 using JavaScript on a WEBM video I am trying to display a
Trying to do a simple drag and drop example in HTML5 - but when
I'm trying to resize a HTML5 canvas element using jQuery. (NOTICE: Not the objects
I'm trying replace HTML5 Canvas to simple <div> But I don't know how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.