- This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › jQuery: keypress event should only function once
Hi,
I’m using a keypress event on a input type=text. When someone is starting to type the keypress is started and will put a textarea into the document. But it should only do this ones. Now it does it with every key that is pressed. So I get as many textarea’s with every letter I’m typing of my sentence.
We’d need to see a link but it sound to me as though your jQuery is not specific enough in it’s targeting.
If you go to: http://popaquestion.com/kaj/ and start typing, then you will see.
Not sure what you are trying to do… but you could remove the event listener in the event callback, but everything inside http://popaquestion.com/kaj/js/animatie.js will only fire once then.
$(‘input’).bind(‘keyup’,function(event){
//Show second input
$(this).unbind(event);
});
Thanks guys, will try these methods today!
I used the solution of @Hompimpa. It works. Thanks. I’m just starting with learning jQuery.
I used following
if($($(this)).val().length ==1),Because I am lazy