MacMan MacMan - 29 days ago 4
jQuery Question

JQuery - Access function from within plugin?

I'm trying to call a function from within a jquery plugin.

The example code is:

onDragClass: "myDragClass",

onDrop: function(table, row) {
var rows = table.tBodies[0].rows;
var debugStr = "Row dropped was "". New order: ";
for (var i=0; i<rows.length; i++) {
debugStr += rows[i].id+" ";

onDragStart: function(table, row) {
$(#debugArea).html("Started dragging row ";

The definition of onDrop taken from


Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table and the row that was dropped. You can work out the new order of the rows by using

Is it possible to pass a function to this ?
eg :

onDrop: doWork(table, row),

Where doWork is:

function doWork (table, row) {
var row_id = $(row).prop('id');

The error is get is:
Uncaught ReferenceError: table is not defined(…)
which relates to the line I added for doDrop.

Anyone know anyway to do this ?


When you write

onDrop: doWork(table, row),

You are calling the function doWork with those parameters. As table doesn't exists it throws the error.

The correct way to do what you are trying is

onDrop: doWork,

This way you are setting the function you want to call.