rodolfo navalon
rodolfo navalon

Reputation: 193

First letter in INPUT doesn't show up in $().keydown of jQuery

I am stuck with this for hours and I cant figure it out why is that when I enter a letter in the input and call the $().keydown of jQuery and alert it with the $(this).val(), the first letter that I inputted won't show up but when you input a letter again it shows up.

Is there any explanation for this?

<div class="mainboxforfriendfind">
    <div class="findfriend">
        <input type="text" id="findtext" name="friendfinder" placeholder="Enter Text to find a friend"/>
        <button id="buttonfriend" class="findfriendbutton"></button>
    </div>
    <div class="outputfindfriend">  
    </div>
</div>
<script>
    $("#findtext").keydown(function () {
        alert($(this).val());
    });
</script>

Upvotes: 0

Views: 175

Answers (1)

Adil
Adil

Reputation: 148160

Use keyup instead of keydown

$("#findtext").keyup(function () {

    alert($(this).val());

});

Upvotes: 2

Related Questions