Comments (6)
I also tried to use an event handler as so:
function foo(){
var buttons = $(document.body).find('.elem1 , elem2');
var myEventHandler = function(){
//some code...
buttons.off('click', myEventHandler);
}
buttons.on('click', myEventHandler);
}
but with no avail, the result was the same as i got with the one()
function where only the pressed button got the event removed from it
from jqlite.
Hi @RongBranovate, this is a hard question.
It was hard because handler is embeded into a function autoDetach(handler) wrapper. So the handler is not the function that is attached.
Finally I've created a onceListeners collector and is passing tests for release: v0.2.12
please tell me if is working for you. And thanks, as always!!
from jqlite.
Hi @jgermade, this is still an issue.
I am using the first method i describered and from what i'm seeing, in jqlite.js
lines 1242-1245:
var index = onceListeners.indexOf(listenerData);
if( index >= 0 ) {
onceListeners.splice(index, 1);
}
If i have 2 elements with that event the onceListeners.splice
only removes one of them(the one that got pressed), the other one is still assigned and will fire when pressed.
from jqlite.
Hi @RongBranovate , I think this is the expected behavior (like jquery).
Maybe this snippet can help you:
<div>
<button class="once">Button 1</button>
</div>
<div>
<button class="once">Button 2</button>
</div>
<div>
<button class="once">Button 3</button>
</div>
<div>
<button class="once">Button 4</button>
</div>
<br/>
<div>
<button class="reset">Reset</button>
</div>
$(function () {
var jButtons = $('button.once');
function clickOnce (e) {
alert('clicked ' + e.target.textContent);
jButtons.off('click', clickOnce);
}
jButtons.one('click', clickOnce);
$('button.reset').click(function () {
jButtons.off('click', clickOnce);
jButtons.one('click', clickOnce);
});
});
from jqlite.
Hi @jgermade
YES! This worked! thanks alot!
from jqlite.
thanks you @RongBranovate !!
from jqlite.
Related Issues (20)
- add .hide() and .show() function HOT 6
- add the .add() function HOT 3
- adding CSS functionality HOT 3
- add .prev() , .prevAll() , .siblings() functions HOT 4
- binding and unbinding keypress HOT 9
- How to use with browserify HOT 6
- Data API should be stored object HOT 3
- Style change event detection HOT 1
- filterDuplicated Error HOT 1
- Re-consider ListDOM'a array-like object implementation HOT 2
- How to avoid collision with Jquery HOT 22
- Adding WrapAll() and unWrap() function HOT 2
- Unbind all listeners of the same event type HOT 10
- Supporting extend method HOT 6
- considering add dataset, classList polyfills HOT 2
- "hasClass" logic in toggleClass function HOT 3
- classListMethods never declared HOT 1
- TypeError: Cannot read property "prototype" from undefined HOT 4
- Minified jqlite does not work in browser HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jqlite.