.Each in two elements with values in different variables

Asked

Viewed 53 times

1

I have two elements, horaFim and horaInicio that are two inputs and both have the class hour.

With each need to have the value of the two separated into variables.

$('.hora').each(function (){
  var horaFinal = $('.horaFinal').val();
  var horaInicio = $('.horaInicio').val();
})

But when I do that my inputs are empty.

  • Can you explain in what context you’re using that code? put what’s around it so we can understand the context better.

  • 1

    What is the purpose? are only two inputs.

1 answer

2

If you know that there are only two inputs one for initial and one for final you do not need to go through with each

Just take the first and last element with the class hora:

var horaInicial = $('.hora').first().val();
var horaFinal = $('.hora').last().val();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.