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

  • SEARCH
  • Home
  • 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 9202199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:11:55+00:00 2026-06-17T23:11:55+00:00

What I have: I have a draggable div with a revert parameter set as

  • 0

What I have:

I have a draggable div with a revert parameter set as “invalid”.

What I need:

When the revert occurs I want to trigger a CSS change to another element.

The problem:

“revert” is parameter rather than an event so I’m experiencing great difficulty in triggering the required CSS change when the revert occurs.

My code:

$('#peg_icon').draggable({
    revert: 'invalid',
    scroll: false,
    stack: "#peg_icon",
    drag: function(event, ui) {
        $('#peg_icon').css('background-image','url(images/peg-icon-when-dragged.png)');
    }
});

What I’ve tried:

I’ve unsuccessfully attempted using “revert” as an event:

revert: function(event, ui) {
    $('#peg_icon').css('background-image','url(images/peg-icon-default.png)');
},

I’ve also unnsuccesfully tried to get the revert paramater to take this function:

function(socketObj)
  {
     //if false then no socket object drop occurred.
     if(socketObj === false)
     {
        //revert the peg by returning true
        $('#peg_icon').css('background-image','url(images/peg-icon-default.png)');
        return true;
     }
     else
     {
        //return false so that the peg does not revert
        return false;
     }
  }

Context:

I’m dragging a div that when dragged, the background-image changes and when the drag reverts, the background-image is restored to its original state.

My question:

How do I trigger a CSS change to another element when revert occurs on a drag?

  • 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-06-17T23:11:56+00:00Added an answer on June 17, 2026 at 11:11 pm

    It turns out that revert can accept a method. See this for a complete example:
    http://jsfiddle.net/mori57/Xpscw/

    Specifically:

    $(function() {
        $("#ducky").draggable({
            revert: function(is_valid_drop){
                console.log("is_valid_drop = " + is_valid_drop);
                // when you're done, you need to remove the "dragging" class
                // and yes, I'm sure this can be refactored better, but I'm 
                // out of time for today! :)
                if(!is_valid_drop){
                   console.log("revert triggered");
                    $(".pond").addClass("green");
                    $(this).removeClass("inmotion");
                   return true;
                } else {
                    $(".pond").removeClass("green");
                    $(this).removeClass("inmotion");
                }
            },
            drag: function(){
                // as you drag, add your "dragging" class, like so:
                $(this).addClass("inmotion");
            }
        });
        $("#boat").droppable({
          drop: function( event, ui ) {
            $(this)
              .addClass("ui-state-highlight");
          }
        });
      });
    

    Hope this helps… I’m guessing that whatever you were trying to modify was the issue, not the attempt to use revert with a function call. Take a look again at what CSS you were trying to set, and see if maybe your issue was in there.

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

Sidebar

Related Questions

I have some particular need to clone an element (image) and be draggable inside
I have a draggable object (div), and some droppable ones (table TD's). I want
I have an element on my page that I want to make draggable. On
I have a jquery draggable div and i want the position to be saved
I have an element, let's say a div, that I want to be able
I have a problem where I need to change the html of a draggable
I have a draggable div element with a hover style. This works fine, but
I have multiple JavaScript draggable DIV windows. When clicking a DIV, I want the
I have set an opacity to a draggable div, but the problem is that
In my case, i have some div and img tags. I am applying draggable

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.