I have a template file which gets dynamically included inside two or more DIV in single page:
divs will be AS below :
1. VIEW div
2. EDIT div
other can be - RESOLUTION div ...
EDIT div is display none while VIEW div appear and reversal. so, only one can be appear at a time.
template file contains below javascript:
AJS.$(document).on('click', '#addROW', function()
{
console.log('calling');
....
..
}
now, when i click on add button (existed in template file) then it executes above event and it should add a single row and print a log message but, it executes doubles so, initially executes two times (as template included in two screens) and prints two times message 'calling' and after some times, it gets double 4 times executes. I expect it should executes one time only and prints 'calling' message once only.
How can i resolve this issue.
It looks like due to javascript is added multiple times.. but how can i control to add it single times into the page or any other way to resolve this issue ?
Thank You
_.debounce(yourFunction)for this issue. There is also a_.once(yourFunction)and a_.throttle(yourFunction). Code is available (MIT-license), usually pretty short: underscorejs.org/#debounce