Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a jQuery plugin work on multiple elements at the same time?

Tags:

I've made a combobox-plugin. To use it, you just have to call

$(elem).combobox(compensateElement);

EDIT: Problem is that if you do

$('#1').combobox('form');
$('#2').combobox('form');

the plugin will break...

The elem is the select to be turned into a combobox, and the compensateElement is an element after which the plugin can insert a div that is the length of the suggestionsDiv-20px high. (I have a footer on my page that isn't pushed down by absolute positioned elements...)

Now, the problem is that this plugin can ONLY BE USED ON ONE ELEMENT! How can it be changed so it can work on multiple elements at once? It's more than a hundred lines of JS-code, so I do not expect the "converted" code!

I've thought of putting all element-specific variables into the this.data "object", but it didn't feel at all like a good solution. After running some RegEx find&replace on it and configuring it for a couple of hours, I didn't get it to work at all...

What techniques can I use?

Thank you very much for your time!