Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is it possible that calling same function more than once makes click events in this function execute also more than one time?
If you are binding an event handler in a function, and you call that function multiple times then yes, every time a click event occurs the handler will be called once for each registration.
Your question is extremely unclear.
It sounds like you're asking whether it's possible to bind multiple handlers to the same event.
Yes; every time you call .on() or similar methods, you will add another event handler.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What's the best way to implement this:
I have multiple elements that will need to do some sort of calculations whenever a global event happens (ex. resize, scroll).
I can either
Add each element to an array then have a single listener for the event and whenever it happens, run a handler that takes the array and loop through each to perform its calc
or
Have each element listen to the single global event
Is there any methods I'm missing?
Add each element to an array then have a single listener for the event
and whenever it happens, run a handler that takes the array and loop
through each to perform its calc
- this; attach a single event handler to a document/body element and do whatever you want in it.
Why: because it has less memory/performance overhead and is a lot more maintainable (which is, in case of JavaScript, often overweights everything else).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
When would you ever use the Event Flow is an application? What I'm referring to is the third parameter of the AddEventListener function. Can anyone provide a real world example?
There aren't a lot of reasons to use event capturing instead of event bubbling. Furthermore, event capturing isn't supported in IE8.
For more info, this page deals with the differences between bubbling/capturing.
In practice, the only reason that I can think of to use event capturing is to deal with events that don't bubble, namely onfocus and onblur. See also this SO post dealing with onblur
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want stop event propagation to only on function in the code instead of stopping and not the rest of the events triggered it is not possible using e.stopeventporpogation
You can't restrict it to single function, instead what you can do is to write the function to be triggered before e.stopeventpropogation and the rest can be after that line
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When binding event handlers, I've found the need to create a function, since it would need to be referenced twice; once initially, and once to the event binding:
// Define function
function doSomething(){...}
// Call function initially
doSomething();
// Pass function as the event handler
$("#theElement").on("click", doSomething);
But then I realized I could start doing this by passing a self-invoking anonymous function as the event handler and returning arguments.callee:
// Much cleaner!
$("#theElement").on("click", (function(){
...
return arguments.callee;
})());
Assuming that I do not ever use this function outside of these two instances, is it an okay practice to do so?
Well, most people would just stick with the first block, because it is clear, simple, and idiomatic. The second block saves one line of code, but the cost is code that does something strange. If your code does something strange then a lot of readers are likely to misunderstand its behavior and any changes they make will be likely to introduce defects.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I was wondering, what happens when a button is pressed and the specified "onkeyup" script is triggered while that script is running?
Thanks for your time!
When you have a function, that is bound to an event, and this event triggers, then this function will run as many times, as the event triggers. So if you trigger keyup event 5 times, the corresponding function will run 5 times as well.
If you want to avoid it, you should do some checkout. For example, I often do it, when work on some sliders. Here's an example:
$('.selector').click( function() {
if ( ! $(this).is(':animated') ) {
// further actions will occur, only if the ".selector" is NOT animated,
// regardless how many times you click it.
}
});