Hi James, I understand that I can do what you suggested (event
delegation,) but I tested a test page with similar conditions and
found that delegating and re-delegating took too long at runtime.  It
took about the same time whether I am using one controller function or
not.  But I am sure I will do the one-controller function on any
future development.  The page loads very quickly though, even with
that many event functions bound to elements.  This page is prepared in
C#.

As to the global variable, well that did not seem to work as I tried
this (and many other things - even the one-controller function -
before I posted to this forum.)  I don't completely understand the
scope of a variable declared outside of all functions in a javascript
file, but it seems that every script "execution" has its own scope
whereby all vars are scoped within it (if that makes any sense), thus
rendering a separate execution scope if I were to simultaneously click
on another element.  "global" scoping is probably different from my
understanding of it.

I tried something along the lines of:

var working = false;

function foo() {
   if (working) return;
   working = true;
   // do stuff
   working = false;
}

to no avail.

But I will learn as I stumble, slowly but surely.
jake


On May 27, 3:53 pm, James <james.gp....@gmail.com> wrote:
> How about setting a global variable such that it will be 'on' when a
> function is running, and set back to 'off' when done?
> Whenever a function sees that it's 'on' it will not execute.
>
> Aside from that, knowing you have so many elements with an onclick
> event, is there any other way to re-work your design so that it can
> use the same function?
> Javascript doesn't have function overloading (creating functions with
> the same name but with different number of arguments), but since you
> can pass in as much arguments as you want into a function, you can do
> an argument count (or type) check and determine what you want to do.
> Alternatively, if possible, store your parameter content separately
> (e.g. a JSON object) that can be referenced to from a specific element
> (e.g. by an ID).
>
> The reason you'd probably want to combine it into one controller
> function is so that you can bind that one controller function to your
> page using event delegation. I'm not sure what you're doing now, but I
> assume you're binding onclicks one-by-one onto every element. Doing
> this with hundreds of elements makes your page load very slow. Event
> delegation binds it only once to the parent element of all those
> elements. Then when the child element is clicked, it will delegate the
> event to the parent. Then you do checks in the function to determine
> which child was clicked on (using the event object that's
> automatically created), and when you get that, you can act on it along
> with the data associated to it.
>
> Here's some reference on event 
> delegation:http://www.learningjquery.com/2008/03/working-with-events-part-1http://lab.distilldesign.com/event-delegation/
>
> Hope that helps.
>
> On May 27, 7:58 am, con-man-jake <jakedim...@gmail.com> wrote:
>
> > I am new to jquery and to web development in general.
> > I have many elements (over 100) on a page each with an onclick event
> > listener function.  They have different listener function names and
> > varying number of parameters.  The functions may take a second or two
> > to process.  If I click on any one of them, I need to disable the
> > mouse click on all the rest until the process is done.
> > Using bind() and unbind() is unrealistic (at least as far as my
> > limited understanding of them is concerned) because of all the
> > different function names and different number of parameters for each.
> > I say 'unrealistic', but, of course, I may be way-off here.
> > So my question is; is there a jquery trick, a javascript trick or even
> > a css trick that can help me do this easily?
> > Your help is greatly appreciated.
> > jake

Reply via email to