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 7044543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:25:20+00:00 2026-05-28T02:25:20+00:00

I have a draggable div of which when you drop it, it gives you

  • 0

I have a draggable div of which when you drop it, it gives you its left and top value and if it contains a specific class.

Example:

$( "div" ).draggable({ 
    cursor:'move',
    stop: function() {

        if ($(this).hasClass('cool')) {
            var state = "Class cool exists"
        }
        var b = $(this);
        var bl = b.offset().left;
        var bt = b.offset().top;
        console.log("  Left:" + bl + "  Top:" + bt + "  Class:" + state);    


    }});

and Fiddle: http://jsfiddle.net/sq4XZ/

Now this works just find but I want to call all those methods in a seperate function because in my actual script I have to call that function many times with button clicks, hovers and basically not just with you drop the div.

So what i did was this:

function cool(){

        if ($(this).hasClass('cool')) {
            var state = "Class cool exists"
        }
        var b = $(this);
        var bl = b.offset().left;
        var bt = b.offset().top;
        console.log("  Left:" + bl + "  Top:" + bt + "  Class:" + state);    

}

$( "div" ).draggable({ 
    cursor:'move',
    stop: function() {

        cool();


    }});

so that every time I need to get those values I would call cool() function.

jsFiddle: http://jsfiddle.net/5bQ4d/

Now if you are a javascript guru you would should know by now that this shouldn’t work because of $(this). If I replace $(this) with $(‘div’) works just fine. But when I call cool() it doesn’t know which $(this) is.

In my actual page I have many of those divs so when I call cool() I have to pass the div id/name/class of which I am talking about. So, how can I pass the div name/id/class to the cool() function so that it knows that $(this) means the div I clicked/hovered/dropped from?

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-28T02:25:21+00:00Added an answer on May 28, 2026 at 2:25 am

    You can just use Function#call:

    stop: function() {
    
        cool.call(this);
    
    
    }});
    

    This will force this to be the same this inside cool as it is inside stop. http://jsfiddle.net/5bQ4d/1/

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

Sidebar

Related Questions

I have a DIV container which position is absolute and I'm having a draggable
I have a draggable div to which I want to set containment 80% of
I have two li elements which are jQuery draggable. When I drag and drop
i have a requirement in which i have a container div that contains 3
In my case, i have some div and img tags. I am applying draggable
I have a draggable table which all working fine, though I want to be
Basically I have a draggable list which is connected with a sortable list. Works
I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {
I have Drag/Drop functionality in my page embedded using YAHOO.js which is initalized at
I have a widget in which I can drop items into a container. I

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.