I am trying to get all values of a class input fields. but it is return only one fields value
Html code
<div id="mydiv">
<input class="seconds" type="text" value="40">
<input class="seconds" type="text" value="20">
<span class="countdown"></span>
</div>
Javascript code
<script src="{{ asset('js/vendor/jquery-3.1.0.min.js') }}"></script>
<script src="{{ asset('js/jquery.missofis-countdown.js') }}"></script>
<script>
var ek=$('.seconds').val();
console.log(ek);
$( '.countdown' ).countdown( {
from: ek, // 3 minutes (3*60)
to: 0, // stop at zero
movingUnit: 1000, // 1000 for 1 second increment/decrements
timerEnd: undefined,
outputPattern: '$day Day $hour : $minute : $second',
autostart: true,
});
</script>
I want to get values of both input fields having same class
Use map()
to create array of the values
var ek = $('.seconds').map((_,el) => el.value).get()
console.log(ek)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="mydiv">
<input class="seconds" type="text" value="40">
<input class="seconds" type="text" value="20">
<span class="countdown"></span>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With