How can I show a selected date on a div?

1

Good, I have this in my javascript

$('.fe_registro').on('click',function(){
      var res = $('.fe_registro').val();
      document.getElementById('resultado').innerHTML = res;
      console.log(res);
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" value="" name="fe_registro" class="fe_registro" id="fe_registro">
    
    <div id="resultado"></div>

What I want is that when I select a date, I display it on the div but I do not know what I'm doing wrong, on the console if it shows it but once I click it, but what I want is that as soon as I select it the date I display it to me

    
asked by Juan Jose 13.11.2018 в 17:36
source

1 answer

2

Instead of using click use change like this:

$('.fe_registro').on('change',function(){
      var res = $('.fe_registro').val();
      document.getElementById('resultado').innerHTML = res;
      console.log(res);
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" value="" name="fe_registro" class="fe_registro" id="fe_registro">
    
    <div id="resultado"></div>
    
answered by 13.11.2018 / 17:41
source