1

I have a problem while passing extraparameters with jquery trigger function. The extra parameters are not passing. Code :

//click event binding with button goes here
$("#b").bind({ click: 
   function (e, x, y) { 
   alert(x + " " + y);   //here`s the problem, showing undefined (expecting top & left  
}                        //offset() of dropped button 
});

//here making the button draggable for drag drop functionality (applying jquery-ui)
$("#b").draggable({ helper : "clone" });

//here creating a droppable area ( here i am dropping a draggable button)
$(".droppable").live({ mouseenter: function () {
    $(this).droppable({
        accept: "#b",              // accepting only button whose id = b
        drop: function (ev, ui) {
            alert("dropped");      //alert is showing means droppable works fine  
            var y = ui.offset.top;
            var x = ui.offset.left;
            ui.draggable.trigger("click", [x , y]); // here i am triggering the click event
        }                                           // for button and passing x and y as an     
    });                                             // extra parameter 
}
});
2
  • For your information, those comments' syntax is amazingly wrong. And by the way, the code should be working (after dropping the comments) Commented Sep 14, 2012 at 22:39
  • have you tried $(this).click(); ? Commented Sep 14, 2012 at 22:39

1 Answer 1

1

I plotted the situation and it works fine for me (With the same code).

What are the elements that are draggable and droppable ? Mine are :

    <div id="b" style="width:200px;height:200px;background-color:red"></div>

    <div class="droppable" style="width:400px;height:200px;background-color:green"></div>

My suggesstions :

Add console.log(x, y) after you get the offset values - there's a chance that the draggable element does not have them (and the values are undefined)

Alter your click handler the following way, so you can handle both user clicks and trigger clicks:

function (e, x, y) { 
                if(typeof x !== "undefined" && typeof y !== undefined) {
                    // do trigger logic
                    return;
                }
                // do click logic
            }
Sign up to request clarification or add additional context in comments.

1 Comment

Nice addition to use console.log() to check parameter is going through before doing anything else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.