jQuery addClass example
Change class name on click in jQuery
by Diman0o
HTML
<div id="banner-message">
<p>Hello World</p>
<div class="row">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
<input type="text" class="input-code" aria-label="Amount (to the nearest dollar)">
</div>
<p id="result"></p>
</div>
JavaScript
function change() {
$('.input-code').on('input ', function (element) {
$(element.currentTarget).next(".input-code").focus();
//alert($(element.currentTarget).val());
checinput();
clear_input();
/* $('#result').html('111') */
/* $(element.currentTarget).next.focus() */
/* alert('focus') */
});
};
function checinput() {
$.each($('.input-code'), function (key, value) {
console.log(key + ": " + value.value);
$('#result').html($('#result').html() + String(value.value));
/* $('#result').tml(result) */
});
if ($('#result').html().length == 4) {
alert('Готово');
}
};
function clear_input(){
/* $("div").prev() */
}
$(document).ready(function () {
change();
});