0

i don't get any error message in my console, but .focus() function in JQuery isn't work. i'm used 2 function that is .focus and .val('')... .val('') is working fine, but .focus() isn't work

here's my HTML code :

    $('.sukses').show(function(){
       var notif = 'some message'; 
       $('.notif').html(notif);
    });    
    $('#kode').focus();
    $('.kode_guru').val('');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="alert alert-success sukses" style="display: none">
        <strong>Success!</strong><p class="notif"></p>
    </div>

    <form action="#" id="form" class="form-horizontal" role="form">
       <input onblur="this.focus()" type="text" name="guru" id="kode" class="kode_guru">
    </form>

my program flow is, when something change in my textfield ('.kode_guru'), the notif will come out and text field will reset to '' and automaticly focused again for another input

hope you guys understand what i'm talking about thanks

1 Answers1

0

I hope you are talking about something like this:

$('.kode_guru').on('change', function() {
  $('.sukses').show(function() {
    var notif = 'some message';
    $('.notif').html(notif);
  });
  $('#kode').focus();
  $('.kode_guru').val('');
});

Here's the fiddle

Saurabh Sharma
  • 2,422
  • 4
  • 20
  • 41